Typically.NET handles the post back event on a button by making the button a type=”submit”:
<input type="submit" Text="Delete" />
However, I’ve recently bumped into a situation where .NET is handling the post back by making the input a type=”button” and then adding a javaScript onClick event to do the “__doPostBack()” – so you end up with this:
<input type="button" onClick="__doPostBack(...);" />
The problem with this is trying to add confirmation messages to the click. So with the 2nd scenario, I end up with this:
<input type="button" onClick="return confirm('Are you sure?'); __doPostBack(...);" Text="Delete" />
Of course, in the above scenario the postback will never happen.
What I’m wondering is why .net chooses one scenario over there other and is there a way to prevent the 2nd?
Thanks
The answer to this is:
.Net uses __doPostBack(…) in the onClick event when working in an ajax scenario.