title: How can I put a jQuery function into my code behind?
body: <p>I have the jQuery function below (<code>Show_popupWindows</code>) :  </p>
  
  <pre><code>    $(function () {
                          var popupWindows_Done = $('input[type="hidden"]#hfpopupWindows_Done').val();
                          if (popupWindows_Done == "false") {
                              Show_popupWindows();
                          }
                          else {
                          }
      });    //End Of $(function ()
      //&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
                  function Show_popupWindows() {
                      var x = screen.availWidth;
                      //alert(x);
                      $('div#OffDiv').css({ 'width': x });
                      //alert($('div#OffDivAndLoadingContainer').css('width'));
                      var y = screen.availHeight;
                      //alert(y);
                      $('div#OffDiv').css({ 'height': y });
                      //alert($('div#OffDivAndLoadingContainer').css('height'));
  
                      //alert('On');
                      $('div#OffDiv').css({ 'display': 'block' });
                      $('div#TimerContainer').css({ 'display': 'block' });
  
                      var w1 = window.open('http://www.blablabla.com', '_blank', 'channelmode=no,directories=yes,location=no,resizable=yes,titlebar=yes,menubar=no,toolbar=no,scrollbars=yes,status=yes', false);
                      var w2 = window.open('http://www.blablabla.com', '_blank', 'channelmode=no,directories=yes,location=no,resizable=yes,titlebar=yes,menubar=no,toolbar=no,scrollbars=yes,status=yes', false);
                      window.focus();
  
                      var sec = $('#TimerContainer span').text()
                      var timer = setInterval(function () {
                          $('#TimerContainer span').text(--sec);
                          if (sec == 0) {
                              clearInterval(timer);
                              $('div#OffDiv').css({ 'display': 'none' });
                              $('div#TimerContainer').css({ 'display': 'none' });
                          }
                      }, 1000);
  
                      var watchClose = setInterval(function () {
                          try {
                              if (w1.closed || w2.closed) {
                                  clearTimeout(watchClose);
                                  clearInterval(timer);
                                  DoNotClosePoPupWindowDuringTimer();
                              }
                          }
                          catch (e) {
                          }
                      }, 200);
                  }
      //&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
  </code></pre>
  
  <p>how can I put this function into my code behind, so nobody can change this function by editing aspx file.</p>
  
  <p>I tried the method below in code behind :  </p>
  
  <pre><code>private static StringBuilder Create_ShowpopupWindows_Function()
  {
      StringBuilder sb = new StringBuilder();
      sb.Append("var x = screen.availWidth;");
      sb.Append("//alert(x);");
      sb.Append("$('div#OffDiv').css({ 'width': x });");
      sb.Append("//alert($('div#OffDivAndLoadingContainer').css('width'));");
      sb.Append("var y = screen.availHeight;");
      sb.Append("//alert(y);");
      sb.Append("$('div#OffDiv').css({ 'height': y });");
      sb.Append("//alert($('div#OffDivAndLoadingContainer').css('height'));");
  
      sb.Append("//alert('On');");
      sb.Append("$('div#OffDiv').css({ 'display': 'block' });");
      sb.Append("$('div#TimerContainer').css({ 'display': 'block' });");
  
      sb.Append("var w1 = window.open('http://www.almasafzar.com', '_blank', 'channelmode=no,directories=yes,location=no,resizable=yes,titlebar=yes,menubar=no,toolbar=no,scrollbars=yes,status=yes', false);");
      sb.Append("var w2 = window.open('http://www.soscharge.com', '_blank', 'channelmode=no,directories=yes,location=no,resizable=yes,titlebar=yes,menubar=no,toolbar=no,scrollbars=yes,status=yes', false);");
      sb.Append("window.focus();");
  
      sb.Append("var sec = $('#TimerContainer span').text()");
      sb.Append("var timer = setInterval(function () {");
      sb.Append("$('#TimerContainer span').text(--sec);");
      sb.Append("if (sec == 0) {");
      sb.Append("clearInterval(timer);");
      sb.Append("$('div#OffDiv').css({ 'display': 'none' });");
      sb.Append("$('div#TimerContainer').css({ 'display': 'none' });");
      sb.Append("}");
      sb.Append("}, 1000);");
  
      sb.Append("var watchClose = setInterval(function () {");
      sb.Append("try {");
      sb.Append("if (w1.closed || w2.closed) {");
      sb.Append("clearTimeout(watchClose);");
      sb.Append("clearInterval(timer);");
      sb.Append("DoNotClosePoPupWindowDuringTimer();");
      sb.Append("}");
      sb.Append("}");
      sb.Append("catch (e) {");
      sb.Append("}");
      sb.Append("}, 200);");
      return sb;
  }
  </code></pre>
  
  <p>but it does not work when I call it in page_load : </p>
  
  <pre><code>        protected void Page_Load(object sender, EventArgs e)
          {
              StringBuilder sb = Create_ShowpopupWindows_Function();
              ScriptManager.RegisterStartupScript(this, this.GetType(), "Show_popupWindows", sb.ToString(), true);
          }
  </code></pre>