Why my jquery code doesn't work with updatepanel post back?

Why my jquery code doesn't work with updatepanel post back?

Hello,
I'm new to jquery. I want to use jquery mask function to format my input.
Here is my original code:
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head runat="server">
  3.     <title></title>
  4.     <script src="../Scripts/jquery-1.11.3.js" type="text/javascript"></script>
  5.     <script src="../Scripts/jquery-maskmoney-3.0.2.js" type="text/javascript"></script>
  6.     <script type="text/javascript">       
  7.         $(document).ready(function() {
  8.             $('#<%=TextBox1.ClientID%>').attr('maxlength', 8).maskMoney({prefix:'$',thousands:',',precision:0,'placeholder':''});
  9.         });
  10.     </script>
  11. </head>
  12. <body>
  13.     <form id="form1" runat="server">
  14.     <asp:ScriptManager ID="SM" runat="server"></asp:ScriptManager>
  15.     <asp:UpdatePanel ID="upMain" runat="server" UpdateMode="Conditional">
  16.         <ContentTemplate>
  17.             <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  18.             <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
  19.         </ContentTemplate>
  20.     </asp:UpdatePanel>
  21.     </form>
  22. </body>
  23. </html>
This code doesn't work with my solution. so I change jquery part of code to the following code, then it works with first page load.
  1. <script type="text/javascript">       
  2.         jQuery(document).ready(function($) {
  3.             $('#<%=TextBox1.ClientID%>').attr('maxlength', 8).maskMoney({prefix:'$',thousands:',',precision:0,'placeholder':''});
  4.         });
  5.     </script>
But it still doesn't work with post back. So I reference this link:  Working with jQuery within the ASP.NET UpdatePanel.
I change my jquery code to the following:
  1. <script type="text/javascript">       
  2.         function InIEvent() {
  3.             $('#<%=TextBox1.ClientID%>').attr('maxlength', 8).maskMoney({prefix:'$',thousands:',',precision:0,'placeholder':''});
  4.         }
  5.         $(document).ready(InIEvent);
  6.     </script>
and change html page to:
  1. <form id="form1" runat="server">
  2.     <asp:ScriptManager ID="SM" runat="server"></asp:ScriptManager>
  3.     <script type="text/javascript">
  4.         Sys.WebForms.PageRequestManager.getInstance().add_endRequest(InIEvent);
  5.     </script>
  6.     <asp:UpdatePanel ID="upMain" runat="server" UpdateMode="Conditional">
  7.         <ContentTemplate>
  8.             <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  9.             <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
  10.         </ContentTemplate>
  11.     </asp:UpdatePanel>
  12.     </form>
Now all my code even doesn't work with first page load. So my question is what's the difference between
  1. jQuery(document).ready(function($) {
  2.             $('#<%=TextBox1.ClientID%>').attr('maxlength', 8).maskMoney({prefix:'$',thousands:',',precision:0,'placeholder':''});
  3.         });
and 
  1. function InIEvent() {
  2.             $('#<%=TextBox1.ClientID%>').attr('maxlength', 8).maskMoney({prefix:'$',thousands:',',precision:0,'placeholder':''});
  3.         }
  4.         $(document).ready(InIEvent);
Is there anything wrong with my code? Same code works with a brand new application.
Thanks for your helping.