title: Run jQuery function on PostBack (ASP.NET)
body: <p>I have a form which is initially hidden via jQuery, and on click of a button two radio buttons appear (also hidden initially via jQuery). On click of one radio button, the user is redirected to another page (this works fine). On click of the other radio button "the form" is made visible again, via jQuery.</p>
  
  <p>My problem comes when a field within 'the form' is validated server-side on submit, and the page is reloaded with the validation error message visible BUT the 'form' is now hidden (as per the  initial jQuery below).</p>
  
  <p>How can I make the form visible on postback? 
   (I have already tried ASP Panels &amp; AJAX UpdatePanel to no avail.)</p>
  
  <p>** This is my jQuery: **</p>
  
  <pre><code>// Reveal Radio Fields
        $(".btn-leavecomment, .txt-leavecomment").toggle(function(){   
              $("#commenttype").stop().animate({ down: "+=300" }, 3000)      
              $("#commenttype").stop().slideDown("slow");      
         }, function(){
              $("#commenttype").stop().animate({ down: "-=300" }, 1400)      
              $("#commenttype").stop().slideUp("slow");  
        });     
  
  
        // Reveal Form on-click of one radio field in particular
        $(".reveal_ccform").toggle(function(){   
              $("#ccform_container").stop().animate({ down: "+=300" }, 4000)      
              $("#ccform_container").stop().slideDown("slow:4000");      
         }, function(){
              $("#ccform_container").stop().animate({ down: "-=300" }, 4000)      
              $("#ccform_container").stop().slideUp("slow:4000");
        }); 
  </code></pre>
  
  <p>Newly Added JavaScript implementation (as per Moar's suggestion) this is still not working, any ideas? :( :</p>
  
  <p>JavaScript:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          $(document).ready() {
              function isPostBack() 
              {
                  if (!document.getElementById('clientSideIsPostBack'))
                  {
                      return false;
  
                      if (document.getElementById('clientSideIsPostBack').value == 'Y' )
                      return true;
                      }
  
                  // Reveal Comment Type
                  $(".btn-leavecomment, .txt-leavecomment").toggle(function () {
                      $("#commenttype").stop().animate({ down: "+=300" }, 3000)
                      $("#commenttype").stop().slideDown("slow");
                  }, function () {
                      $("#commenttype").stop().animate({ down: "-=300" }, 1400)
                      $("#commenttype").stop().slideUp("slow");
                  });
  
  
                  // Reveal Sign Guestbook Form
                  $(".reveal_ccform").toggle(function () {
                      $("#ccform_container").stop().animate({ down: "+=300" }, 4000)
                      $("#ccform_container").stop().slideDown("slow:4000");
                  }, function () {
                      $("#ccform_container").stop().animate({ down: "-=300" }, 4000)
                      $("#ccform_container").stop().slideUp("slow:4000");
                  });
  
                  // Hide 'Leave a Comment' button and 'Comment Type' div
                  $('.reveal_ccform').click(function () {
                      $(".btn-leavecomment").stop().fadeOut("slow:1500"),
                      $('#commenttype').slideUp("slow:8000");
                  });
              }
          }
      &lt;/script&gt;
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>if (Page.IsPostBack)
          {
              Page.ClientScript.RegisterStartupScript(GetType(), "IsPostBack", script, true);
  
              //Second part of code will run if is postback = true
              ClientScriptManager cs = Page.ClientScript;
              Type csType = this.GetType();
              cs.RegisterClientScriptBlock(csType, "openForms",     "$(document).ready(openForms);", true);
          }  
  </code></pre>