title: using external js to call aspx.cs function (on button click)
body: <p>I am trying to call an aspx.cs function using an external javascript when a button is clicked on.</p>
  
  <p>Here is the aspx  </p>
  
  <pre><code>&lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;link href="style.css" rel="stylesheet" type="text/css" /&gt;
      &lt;script type="text/javascript" src="&lt;%= ResolveUrl ("~/Scripts/lookup.js") %&gt;"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
          &lt;section class="webdesigntuts-workshop"&gt;
              &lt;asp:ScriptManager ID='ScriptManager1' runat='server' EnablePageMethods='true' /&gt;
      &lt;form id="form1" runat="server"&gt;            
          &lt;asp:TextBox type="search" name="search" id="sform" placeholder="What are you looking for?" runat="server" /&gt;       
           &lt;asp:TextBox type="search" name="hdnText" id="hdnText" runat="server" /&gt;
  
          &lt;button id="Button1"  runat="server" onclientclick="lookup();return false;"&gt;Search&lt;/button&gt;
      &lt;/form&gt;
  &lt;/section&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p>Here is my javascript lookup.js which is placed in the Scripts folder.</p>
  
  <pre><code>function Signup() {
      var query = document.getElementById('&lt;%=sform.ClientID %&gt;').value;
  
  
      PageMethods.lookupfromjs_Click(query);
  
      function onSucess(result) {
          alert(result);
      }
  
      function onError(result) {
          alert('Cannot process your request at the moment, please try later.');
      }
  }
  </code></pre>
  
  <p>here is the aspx.cs function.</p>
  
  <pre><code>protected void lookupfromjs_Click(String query)
          {
  
              if (!String.IsNullOrEmpty(query))
              {
                  hdnText.Text = "query= " + query + " look up number " + lookup_no++;
  
                  // sform.Text= "You are looking up the term " + query;
  
              }
          }
  </code></pre>
  
  <p>There are no errors as such in VS or in browser. But my breakpoints in browser dont seem to kick in. The java script is loaded correctly by the browser. However on button click nothing seems to happen.</p>
  
  <p>Any help would be appreciated.</p>