Welcome to AspAdvice Sign in | Join | Help

ASP.NET - INPUT button fire javascript and serverclick

if you encounter problem when you want to use an html buttom control and you wish to fire both javascript and serverclick event, you will notice that you only can fire the javascript event ONLY. inorder for you to fire both the javascript and serverclick event you can try to change the type of input to submit

html
<script type="text/javascript">
function validate()
    {
    if (document.getElementById('TextBox1').value =="")
    {
    alert("Enter value into textbox")
    document.getElementById('TextBox1').focus()
    return false;

    }
    return true;
    }
</script>

<asp:textbox id="TextBox1" runat="server"></asp:textbox>     
<input id="Button1" runat="server" onclick="return validate();" type="submit" value="button" onserverclick="Button1_ServerClick" />

code
protected void Button1_ServerClick(object sender, EventArgs e)
{
        Response.Write("B");
}

Sponsor
Published Saturday, May 09, 2009 9:05 PM by mo meng

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required) 
Enter the code you see below