2010-02-05 106 views
0

我有一個GridView控件,它顯示列Name,Comments,Image。當我點擊一個圖像時,我需要打開一個模態彈出式擴展器,該擴展器將被分配給包含文本框,文件上傳控件,上傳和取消按鈕的面板。在Ajax中使用fileupload控制模式彈出式擴展器

問題是當我按下更新按鈕button_click事件我無法找到FileUpload控件裏面的文件,因爲我可以在文本框內找到任何幫助的讚賞。我的代碼如下:

<asp:GridView ID="gdvMngTeam" runat="server" 
    CellPadding="4" 
    AutoGenerateColumns="False" 
    ForeColor="#333333" 
    GridLines="None" 
    Width="100%" 
    DataMember="ID" 
    OnRowCommand="gdvMngTeam_RowCommand"> 
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> 
    <RowStyle BackColor="#EFF3FB" Font-Names="Verdana" Font-Size="Small" /> 
    <Columns> 
     <asp:BoundField DataField="ID" HeaderText="ID" Visible="False" /> 
     <asp:BoundField HeaderText="Name" DataField="Name" /> 
     <asp:BoundField HeaderText="Comments" DataField="Comments" /> 
     <asp:TemplateField HeaderText="Photo"> 
      <ItemTemplate> 
       <asp:ImageButton ID="imgbtnPhoto" ImageUrl= '<%# Eval("Image") %>' runat="server" CommandArgument='<%# Eval("ID") %>' CommandName="Photo" />     
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> 
    <EmptyDataTemplate> 
     <asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Names="Verdana" Font-Size="Small" ForeColor="Red" Text="No Records Found"></asp:Label> 
    </EmptyDataTemplate> 
    <SelectedRowStyle BackColor="#D1DDF1" ForeColor="#333333" Font-Bold="True" /> 
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" Font-Names="Verdana" Font-Size="Medium" /> 
    <EditRowStyle BackColor="#2461BF" /> 
    <AlternatingRowStyle BackColor="White" /> 
</asp:GridView> 

<tr> 
    <td> 
     <asp:Panel ID="Panel1" runat="server"> 
      <table cellpadding="2" cellspacing="2" border="0"> 
       <tr> 
        <td> 
         <asp:Label ID="Label8" runat="server" Text="Upload Photo :" Font-Bold="True" Font-Names="Verdana" Font-Size="Small" ForeColor="White"></asp:Label> 
        </td> 
        <td> 
         <asp:FileUpload ID="fumdpop" runat="server" /><br /> 
         <asp:TextBox ID="tx" runat="server"></asp:TextBox> 
        </td> 
       </tr> 
       <tr> 
        <td colspan="2" style="line-height: 6px;">&nbsp;</td> 
       </tr> 
       <tr> 
        <td colspan="2" align="center"> 
         <asp:Button ID="btnUpload" runat="server" Text="Upload" onclick="btnUpload_Click" />&nbsp;&nbsp; 
         <asp:Button ID="btnfuCancel" runat="server" Text="Cancel" /> 
         &nbsp; 
         <asp:Button ID="btnok" runat="server" Text="OK" /> 
        </td> 
       </tr> 
      </table> 
     </asp:Panel> 
    </td> 
</tr> 
<tr> 
    <asp:Button ID="bt" runat="server" Text="bt" /> 
    <cc1:ModalPopupExtender ID="mdpextPhoto" BackgroundCssClass="backgroundcolor" runat="server" TargetControlID="bt" PopupControlID="Panel1" OkControlID="btnUpload" CancelControlID="btnfuCancel" > 
    </cc1:ModalPopupExtender> 
</tr> 

後面的代碼:

ScriptManager curObj = ScriptManager.GetCurrent(Page); 
(if curObj != null) 
     current.RegisterPostBackControl(btnUpload); 

和:

protected void gdvMngTeam_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName == "Photo") 
    { 
     ViewState["ID"] = Convert.ToInt16(e.CommandArgument); 

     //AjaxControlToolkit.ModalPopupExtender mpop = (AjaxControlToolkit.ModalPopupExtender)gdvMngTeam.SelectedRow.FindControl(
     mdpextPhoto.Show(); 
    } 
} 

protected void btnUpload_Click(object sender, EventArgs e) 
{ 
    string txt = tx.Text; 
    if(fumdpop.HasFile) 
    { 
     string filename = fumdpop.FileName; 
     fumdpop.SaveAs(Server.MapPath("Photos/" + filename)); 
     objTeam.ID = id; 
     objTeam.Image = "photos/" + filename; 
     string resutl = TeamManager.ChangeImage(objTeam); 

     ds = TeamManager.GetTeamDetails(); 
     gdvMngTeam.DataSource = ds.Tables[0]; 
     gdvMngTeam.DataBind(); 
    } 
} 

回答

3

您應該在ScriptManager

C#註冊FileuploadbtnUploadFullPostBackControl VB:

Dim curObj As ScriptManager = ScriptManager.GetCurrent(Page) 
If curObj IsNot Nothing Then 
     curObj.RegisterPostBackControl(btnUpload) 
End If 
相關問題