Execute Server Side from Client Side
<p>I want to execute the Add button click event(server side) from client side.</p>

<p>This is my javascript function</p>

<pre><code>  function validateinput() {
    var arrTextBox = document.getElementsByTagName("input");
     var retVal = 1;
    for (i = 0; i &lt; arrTextBox.length; i++) {
        if (arrTextBox[i].type == "text"  &amp;&amp; arrTextBox[i].value == "") {
            retVal = 0;

        }
    }


    if (retVal == 0) {
        alert("Validation Failed");
        return false;
    }
    else {
        alert("Validation Success");
        return true;
        __doPostBack(btnAddItem);

    }

}
</code></pre>

<p>I am calling the server side code only when alert("Validation Sucess") and returns true.</p>

<p>This is my server side code </p>

<pre><code>    protected void Page_Load(object sender, EventArgs e)
    {
        txtbox1.Attributes.Add("onkeydown", "if(event.keyCode) {if  (event.keyCode &gt; 57 &amp;&amp; event.keyCode &lt;= 90)  return false; } else {return true};");
        if (!IsPostBack)
        {
            //The code is too big to be posted
        }
    }

    protected void btnAddItem_Click(object sender, EventArgs e)
    {
        if (IsValidPost())
        {
            if (btnAddItem.Text == "Add Item +")
            {
                if (textbox1.text== "")
                {
                    Addtogrid();
                }
            }
        }
    }
</code></pre>

<p>Am I doing it the right way? as I am not getting the expected results. Also I get an error at  Page.GetPostBackEventReference(btnAddItem); saying ClientScript is a recommended way . When I try to use ClientScript.GetPostBackEventReference(btnAddItem); it throws an error stating ClientScript is not recognised.</p>

<p>Please help</p>
