title: Calling server side function with parameter from Javascript in ASP.NET
body: <p>I have an <strong>ASP.NET</strong> application in <strong>VB.NET</strong>. I have a <strong>Javascript</strong> function in <code>mypage.aspx</code> and another one in my <code>callback.aspx</code> page. I need this scripts to render and submit an <code>IFrame</code> on <code>mypage.aspx</code>.</p>
  
  <p>When I click on the submit button:</p>
  
  <pre><code>&lt;asp:Button ID="subbtn" Name="Submit" OnClientClick="onsubmit_action();" runat="server" /&gt;
  </code></pre>
  
  <p>this script is executed, where <code>iframeId</code> is the id of the <code>IFrame</code>:</p>
  
  <pre><code>function onsubmit_action() {
  
              submitPage('iframeId');           
          }
  </code></pre>
  
  <p>The response of the <code>IFrame</code> (validation or success) is submitted to the <code>callback.aspx</code> file. I guess this happens through <strong>cross-site scripting</strong> that calls the callback function in the <code>callback.aspx</code> file;</p>
  
  <pre><code>function callback()
  {
       parent.pagecallback_success('&lt;%=Request.QueryString("Id")%&gt;');
  }
  </code></pre>
  
  <p>that calls the function in <code>mypage.aspx</code></p>
  
  <pre><code>function pagecallback_success(ref_id) {
          var Url = "mypage.aspx?";
          Url += "id=" + id;
          window.location.href = Url;
      }
  </code></pre>
  
  <p>The script works as expected. Now, I would like to call a server function </p>
  
  <pre><code>Protected Function Store(ByVal id As String) As Boolean
  </code></pre>
  
  <p>in <code>mypage.aspx.vb</code> and pass the variable <code>id</code>:</p>
  
  <pre><code>function hostedpagecallback_success(id) {
              var Url = "mypage.aspx?";
              Url += "id=" + id;
              window.location.href = Url;
              "&lt;%= Store(id) %&gt;"
          }
  </code></pre>
  
  <p>The problem is that the compiler considers <code>id</code> as a server side function and gives a compile error. However if I use a <code>sub</code> (without parameters) instead of a function, the <code>sub</code> is executed 3 times, on <code>page_load</code>, when the <code>IFrame</code> is received and another time (connection is https cannot debug <strong>Javascript</strong> efficiently).</p>
  
  <p>I am not good in cross-site scripting and code nuggets, probably it is really trivial but I do not know how to solve this problem. Anybody?</p>