Note that there are some explanatory texts on larger screens.

plurals
  1. POCall C# Function From JavaScript/JQuery In Asp.net webforms
    primarykey
    data
    text
    <p>So, i have an aspx page which looks like this:</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I would like to know, how I can write JavaScript (e.g. jQuery) code that will call a function from my C# Code. Lets say this is my C# method:</p> <pre><code>protected void XXX(object sender, EventArgs e) { Response.Redirect("pagewho?"); } </code></pre> <p>Thanks again, Alon. :)</p> <p>EDIT:</p> <p>This is the full code i am using the moment:</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; validateStuff = function () { var isValid = true; var txt = document.getElementById("TextBox1"); if (txt) { if (txt.value.toLower() != "james") { isValid = false; } } //perform validation and return true/false return isValid; } &lt;/script&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:Button ID="Button1" runat="server" OnClientClick="return validateStuff();" OnClick="Button1_Click" /&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:TextBox ID="TextBox1" runat="server" Height="25px" Width="135px"&gt;&lt;/asp:TextBox&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>but, no matter what i am wireting in the textbox, its return true. any help?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload