jQuery and UpdatePanel in Asp.net. How to make it work

When I created my first Asp.net web application with UpdatePanel, I wanted to use jQuery for some features. I wanted to make a button "transform", and when you click it, the text in UpdatePanel became modified via Javascript. I used jQuery framework also here. Soon I found out that it's not the simple task.
To make jQuery work in UpdatePanel, in tags ContentTemplate you should add strings:
1 |
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(BindEvents); |
Where BindEvents is the JavaScript function with jQuery functions.
After that you should modify your jQuery code. Change the code like this:
1 2 3 4 5 |
$(document).ready(function() { //String of code 1 //String of code 2 //String of code N }); |
To:
1 2 3 4 5 |
function BindEvents() { //String of code 1 //String of code 2 //String of code N } |
In aspx page it's something like this:
1 2 3 4 5 6 |
<ContentTemplate> <script type="text/javascript"> Sys.WebForms.PageRequestManager.getInstance().add_endRequest(BindEvents); </script> <asp:Label ID="swifttextLC" runat="server" Text=""></asp:Label> </ContentTemplate> |