title: Call C# method from asp page .net
body: <pre><code>&lt;asp:TextBox runat="server" ID="textbox2" MaxLength="2" onfocus="textbox2_focus" /&gt;
  </code></pre>
  
  <p>and I have c# codebehind method:</p>
  
  <p><code>public void textbox2_focus(object sender, EventArgs e)
          {
              var x = 5;
          }</code></p>
  
  <p>But This code tries to execute JavaScript Function.
  How to execute c# function from code behind?
  I tried something like:</p>
  
  <pre><code>&lt;asp:TextBox runat="server" ID="textbox2" MaxLength="2" onfocus="&lt;%=textbox2_focus() %&gt;"/&gt;
  </code></pre>
  
  <p>but didn't work.</p>