I have a usercontrol in ASP.Net featuring a button that I use to postback. This button also has some Javascript validation that is done before it processes the event.
Today I tried to postback to another URL by setting the PostBackURL property of the button. But it didn't work and the page kept posting back to itself. So I did some investigation and found that.
- Post back to another URL is implemented through Javascript in ASP.Net.
If I keep the call to my validation function
OnClientClick="return validate()" Then the post back does not occur.
- If I remove the call to the validation function, the postback works fine.
This is how the button markup looks with Validation on.
<input type="submit" name="ctl00$cphMain$pra1$btnSubmit" value="Submit" onclick="return validate();WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$cphMain$pra1$btnSubmit", "", false, "", "Result.aspx", false, false))" id="ctl00_cphMain_pra1_btnSubmit" style="width:80px;" />
Without validation
<input type="submit" name="ctl00$cphMain$pra1$btnSubmit" value="Submit" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$cphMain$pra1$btnSubmit", "", false, "", "Result.aspx", false, false))" id="ctl00_cphMain_pra1_btnSubmit" style="width:80px;" />
You'll notice that the call to 'return validate()' is missing, and that is making all the difference.
How can I get this to work?