简体   繁体   中英

Asp.net button onclick not working in updatepanel

My problem is, the asp button's onclick is not working inside the updatepanel. Basically what my code does is, I have an asp fileupload control to upload a file. And then afterwards, the user can now click the button and the filename of the uploaded file will be displayed in the asp label control.

But when i tried it, it is not displaying the filename in the label. It does nothing.

Here is the aspx:

   <asp:UpdatePanel runat="server" UpdateMode="Always" ID="updPnlName" 
    ChildrenAsTriggers="true">
                         <ContentTemplate>
                              <asp:FileUpload runat="server" ID="Image1"/>
                                   <asp:Button ID="Button2" runat="server" 
                                    Text="Upload" OnClick="Button2_Click"/>
                             </ContentTemplate>
                            <Triggers>
                               <asp:AsyncPostBackTrigger ControlID="Button2" 
                                    EventName="Click"/> 
                            </Triggers>
                     </asp:UpdatePanel>
                     <asp:Label ID="Label3" runat="server" Text="Label">
  </asp:Label>

Here is the code-behind:

public void Button2_Click(Object sender, EventArgs e)
{
    var filename1 = Image1.FileName;
    Label3.Text = "Upload successfull - " + filename1;
}

By the way, the reason why i wanted to use updatepanel is to avoid refreshing the entire page when the user clicked the button. Please kindly help me on this one.

将标签放在UpdatePanel内,这将更新标签控件的文本值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM