Listview中的文件上载问题在Update Panel中的编辑项目模板 [英] Problems With File Upload Within Listview Edit Item Template Within Update Panel

查看:109
本文介绍了Listview中的文件上载问题在Update Panel中的编辑项目模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UpdatePanel内ListView的EditItemTemplate中的FileUpload控件遇到问题. FileUpload.FileName始终为NULL.

我知道文件上载与更新面板不兼容,但是可以使用PostBackTrigger进行纠正.但是,即使使用PostBackTrigger,问题仍然存在.

万分感谢!!

干杯.

约翰

代码如下:

I am experiencing problems with the FileUpload control inside the EditItemTemplate in a ListView inside an UpdatePanel. FileUpload.FileName is always NULL.

I am aware File Upload is not cpmpatible with Update Panels but this can be rectified with use of a PostBackTrigger. However even with a PostBackTrigger problem still persists.

Any help gratefully received !!

Cheers.

John

Code as follows :

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="TestFileUpload.aspx.vb" Inherits="Maint_TestFileUpload" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    
        
        
        <asp:Button ID="btnInsertNew" runat="server" style=" font:  comics sans ms; margin-bottom: 10px" Text="Insert New Image" />

        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        
            <contenttemplate>

            <asp:ListView ID="lvwPics" runat="server" 

                        DataSourceid="sdsPics" 

                        DataKeyNames="PictureId" 

                        InsertItemPosition="None">
            
            <layouttemplate>
              <table ID="itemPlaceholderContainer"  runat="server" style="border: solid 1px; width: 100%"> 
                <thead>
                <tr id="Tr1"  runat="server" class="lvwBasketHdr" > 
                  <td id="Td1"  align="center"  runat="server" >
                    <asp:Label ID="Label1" runat="server" Text="Title / Image"/> 
                  
                  <td id="Td2" align="center"  runat="server">
                    <asp:Label ID="Label2" runat="server" Text="Data Item"/> 
                  
                  <td id="Td4" align="center"  runat="server">
                    <asp:Label ID="Label3" runat="server" Text="Value"/> 
                  
                  <td id="Td5" align="center"  runat="server">
                    <asp:Label ID="Label4" runat="server" Text="Action"/> 
                  
                
                </thead>
                <tbody>
                  <tr   runat="server" id="itemPlaceholder" > 
                  
                </tbody>             
               
                  
            </layouttemplate>
       
       
            
            <itemtemplate>
                <tr style="width:100%">
               
                        <td id="Td3" valign="top" align="center" style="width:25%" rowspan="1">
                          <asp:Label ID="Label5" runat="server"  CssClass="SmallTitle" Text='<% #Eval("Title")%>'>
                          <br />
                          <asp:HyperLink ID="HyperLink2" runat="server" 

                                         ImageUrl='<%#Eval("ThumbnailPath")%>' 

                                         NavigateUrl='<%#Eval("PictureURL")%>' 

                                         ToolTip="Double click to enlarge image">
                          
                          
                          <asp:Label ID="Label6" runat="server"  Visible="false"   Text='<%#Eval("PictureId")%>'/>

                        </td>

                        <td style="height: 1.2em">
                        </td>
                        
                        <td style="height: 1.2em">
                        </td>

                        <td align="center" rowspan="1" style="width:10%">    
                            <asp:Button ID="btnRemove" CommandName="DELETE" runat="server" Text="Remove" CssClass="btnAction" CausesValidation="False" />
                            <asp:Button ID="btnEdit" CommandName="EDIT" runat="server" Text="Edit"  CssClass="btnAction" CausesValidation="False" />
                        </td>
                        
                    
            </tr></itemtemplate>
            <itemseparatortemplate>
                <td colspan="4" style="border-removedsolid 1px silver"> </td>
            </itemseparatortemplate>


            
            <edititemtemplate>
                <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                    <triggers>
                        <asp:PostBackTrigger ControlID="btnUpdate" />
                    </triggers>
                    
                    <contenttemplate>
                            
           
                        <tr style="width:100%">
                   
                            <td id="Td3" valign="top" align="center" style="width:25%" rowspan="1">
                              <asp:Label ID="lblEditTitle" runat="server" CssClass="SmallTitle" Text='<% #Eval("Title")%>'>
                              <asp:HyperLink ID="HyperLink2" runat="server" 

                                             ImageUrl='<%#Eval("ThumbnailPath")%>' 

                                             NavigateUrl='<%#Eval("PictureURL")%>' 

                                             ToolTip="Double click to enlarge image">
                              
                              <asp:Label ID="lblEditPicId" runat="server"  Visible="false"   Text='<%#Eval("PictureId")%>'/>
                            </td>

                            <td class="PicMaintLabel" valign="top" style="width:15%">
                                <asp:Label ID="lblChangeImage" runat="server"  Text="Change Image :"/> 
                            
                            </td>
                            
                            <td style="width:50%" onmouseover="this.style.backgroundColor='#FBF5E6'" önmouseout="this.style.backgroundColor='#FFFFFF'">
                                <asp:FileUpload id="fuEditImage" runat="server" >
                            </td>

                            <td align="center" rowspan="1" style="width:10%">    
                               <asp:Button ID="btnUpdate" CommandName="UPDATE" runat="server" Text="Update" CssClass="btnAction" ValidationGroup="Edit" />
                               <asp:Button ID="btnCancelEdit" CommandName="CANCEL" runat="server" Text="Cancel" CssClass="btnAction" CausesValidation="False" />
                            </td>
                            
                        </tr>
                    </contenttemplate>
                    
                
            </edititemtemplate>

        
                
                <asp:SqlDataSource ID="sdsPics" runat="server" 

                                   ConnectionString="<%$ ConnectionStrings:cnAA %>"  

                                   SelectCommand="SELECT * FROM vwMaintPics "

                                   DeleteCommand="DELETE FROM Pictures WHERE PictureId = @PictureId "

                                   UpdateCommand="UPDATE Pictures 
                                                  SET 
                                                      Title = @Title
                                                   WHERE PictureId = @PictureId" >
                                    
                
                </contenttemplate>




CODE BEHIND




CODE BEHIND

Protected Sub lvwPics_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewUpdateEventArgs) Handles lvwPics.ItemUpdating
    Try
        mfu = CType(lvwPics.EditItem.FindControl("fuEditImage"), FileUpload)
        e.NewValues.Add("PictureId", CType(lvwPics.EditItem.FindControl("lblEditPicId"), Label).Text)
        e.NewValues.Add("Title", mfu.FileName)

    Catch ex As Exception

    End Try
End Sub

推荐答案

ConnectionStrings:cnAA %>" SelectCommand="SELECT * FROM vwMaintPics " DeleteCommand="DELETE FROM Pictures WHERE PictureId = @PictureId " UpdateCommand="UPDATE Pictures 放 Title = @Title WHERE PictureId = @PictureId" > < /contenttemplate >
ConnectionStrings:cnAA %>" SelectCommand="SELECT * FROM vwMaintPics " DeleteCommand="DELETE FROM Pictures WHERE PictureId = @PictureId " UpdateCommand="UPDATE Pictures SET Title = @Title WHERE PictureId = @PictureId" > </contenttemplate>




CODE BEHIND




CODE BEHIND

Protected Sub lvwPics_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewUpdateEventArgs) Handles lvwPics.ItemUpdating
    Try
        mfu = CType(lvwPics.EditItem.FindControl("fuEditImage"), FileUpload)
        e.NewValues.Add("PictureId", CType(lvwPics.EditItem.FindControl("lblEditPicId"), Label).Text)
        e.NewValues.Add("Title", mfu.FileName)

    Catch ex As Exception

    End Try
End Sub


Have noticed that if I remove the outer Update Panel, the code works, that is the File Upload control has a file that can be saved to the server. No problems with File Upload control and the Update Panel it is in.

The reason for the outer Update Panel was to maintain the scroll position when the user scrolls down the screen. Without it the user scrolls down the screen clicks on a EDIT button, a full postback is done and the user is positioned at the top of the listview and not on the record being edited.

Is there another way of maintaining the scroll position in a list view ?

John
Have noticed that if I remove the outer Update Panel, the code works, that is the File Upload control has a file that can be saved to the server. No problems with File Upload control and the Update Panel it is in.

The reason for the outer Update Panel was to maintain the scroll position when the user scrolls down the screen. Without it the user scrolls down the screen clicks on a EDIT button, a full postback is done and the user is positioned at the top of the listview and not on the record being edited.

Is there another way of maintaining the scroll position in a list view ?

John


I have been testing my code in Google Chrome, however as a last straw tried it in IE8 and it works perfectly (just had to tweak the outer Update Panel to have UpdateMode="Conditional".

The issue is not now a problem with the above code but a browser compatibility issue.

Any suggestions how to rectify this ??



John
I have been testing my code in Google Chrome, however as a last straw tried it in IE8 and it works perfectly (just had to tweak the outer Update Panel to have UpdateMode="Conditional".

The issue is not now a problem with the above code but a browser compatibility issue.

Any suggestions how to rectify this ??



John


这篇关于Listview中的文件上载问题在Update Panel中的编辑项目模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆