stop postback in asp.net
-
how do i use my javascript to stop postback in the input is not correct i don't want it to post back to the server here is the code: private void Page_Load(object sender, System.EventArgs e) { // Form the script that is to be registered at client side. String scriptString = " \n"; scriptString += "function DoClick()\n {\n"; scriptString += "\t myForm.show.value='Welcome to Microsoft .NET'; \n "; scriptString += "return true;\n}"; scriptString += ""; if(!this.IsClientScriptBlockRegistered("clientScript")) this.RegisterClientScriptBlock("clientScript", scriptString); button.Attributes["onclick"]="DoClick()"; } here is the html:
Thanks chad -- modified at 22:40 Monday 27th February, 2006
-
how do i use my javascript to stop postback in the input is not correct i don't want it to post back to the server here is the code: private void Page_Load(object sender, System.EventArgs e) { // Form the script that is to be registered at client side. String scriptString = " \n"; scriptString += "function DoClick()\n {\n"; scriptString += "\t myForm.show.value='Welcome to Microsoft .NET'; \n "; scriptString += "return true;\n}"; scriptString += ""; if(!this.IsClientScriptBlockRegistered("clientScript")) this.RegisterClientScriptBlock("clientScript", scriptString); button.Attributes["onclick"]="DoClick()"; } here is the html:
Thanks chad -- modified at 22:40 Monday 27th February, 2006
-
If the input is not correct, return false from the javascript function. --- b { font-weight: normal; }
-
i returned false and a postback stilled happeded i have server side code on this asp.net button which writes "server" in that textbox and i want to be able to stop that from happening thanks chad
-
how do i use my javascript to stop postback in the input is not correct i don't want it to post back to the server here is the code: private void Page_Load(object sender, System.EventArgs e) { // Form the script that is to be registered at client side. String scriptString = " \n"; scriptString += "function DoClick()\n {\n"; scriptString += "\t myForm.show.value='Welcome to Microsoft .NET'; \n "; scriptString += "return true;\n}"; scriptString += ""; if(!this.IsClientScriptBlockRegistered("clientScript")) this.RegisterClientScriptBlock("clientScript", scriptString); button.Attributes["onclick"]="DoClick()"; } here is the html:
Thanks chad -- modified at 22:40 Monday 27th February, 2006
Use if(!Page.IsPostBack) button.Attributes["onclick"]="DoClick()"; Senior Software Engineer