When the UpdatePanel post back triggers, the existing markup will overwrite with the markup generated by UpdatePanel on the post back, which destroys all event handlers from HTML elements in the UpdatePanel.
In example below, I used an asp button for post back event and jQuery to show a message when Click Me! link is clicked.
JavaScript/jQuery function
- <script type="text/javascript">
-
- function calldemo() {
- $("#click").click(function() {
- alert("Clicked Me!");
- });
- }
- </script>
ASP.NET UpdatePanel with JavaScript/jQuery re-call function,
- <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
- <asp:UpdatePanel ID="UpdatePanel1" runat="server">
- <contenttemplate>
- <!--Re-Calling JavaScirpt/jQuery function on each Asynchronous post back.-->
- <script type="text/javascript" language="javascript">
- Sys.Application.add_load(calldemo);
- </script>
- <asp:Button ID="btnPostBack" runat="server" OnClick="btnPostBack_Click" Text="Click To Postback" /> <a href "#" id="click">Click Me!</a> </contenttemplate>
- </asp:UpdatePanel>
ASP.NET (C#) code for button,
- protected void btnPostBack_Click(object sender, EventArgs e)
- {
- btnPostBack.Text = "UpdatePanel PostBack Happened";
- }
Conclusion
After calling JavaScript/jQuery functions inside UpdatePanel using Sys.Applicaiton.add_load() event handler, you will be able to solve the problem.