简体   繁体   中英

Update panel does not respond to button event

Is there any problem with my code? update panel does not show requested label after button click

     <asp:UpdatePanel runat="server" ID="updatesPanel" UpdateMode="Conditional" OnUnload="UpdatePanel_UnLoad">
                <ContentTemplate>
                    <asp:Label ID="lblUpdateSavedSuccess" Text=" Changes Saved Successfully :) " runat="server" Font-Bold="True" 
                        Font-Names="Comic Sans MS" Font-Size="X-Large" ForeColor="#00CC00" Visible="false"/><br />

                    <asp:Label ID="lblUpdateSavedFailed" Text=" Something Went worng :( " runat="server" Font-Bold="True" 
                        Font-Names="Comic Sans MS" Font-Size="X-Large" ForeColor="Red" Visible="false"/><br />

                    <asp:Label ID="lblUpdateNoChanges" Text=" There is now changes :| " runat="server" Font-Bold="True" 
                        Font-Names="Comic Sans MS" Font-Size="X-Large" ForeColor="#0099FF" Visible="False"/>
                    <asp:Button ID="btnUpdateInfo" runat="server" Text ="Save Changes" OnClick="btnUpdateInfo_Click"/>&nbsp;&nbsp;&nbsp;
                    <asp:Button ID="deleteUser" runat="server" Text="Delete User" Width="118px" OnClick="deleteUser_Click" />

                    <br /><br />
                </ContentTemplate>
            </asp:UpdatePanel>

my button event:

    protected void btnUpdateInfo_Click(object sender, EventArgs e)
    {

                lblUpdateSavedSuccess.Visible = true;
                lblUpdateSavedFailed.Visible = false;
                lblUpdateNoChanges.Visible = false;
    }

I have to use OnUnload="UpdatePanel_UnLoad" in my update panel because while complie my work I have an exception releated to unregister updatePanel.

I've tried replicating your problem on my side but everything is working fine.Usually if there are issues with the AJAX controls it's because you have another java script library added to the page which conflicts with the AJAX scrits.You can confirm this by pressing Ctrl+Shift+J in Google chrome while your web page is running and inspecting the browser console.

I've also had issues in the past where the js scripts were not being loaded properly for AJAX and adding EnableCdn="true" to the ScriptManager fixed the probem:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnableCdn="true"></asp:ScriptManager>

Hope this helps you in fixing your issue.

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