How to Override the __doPostBack function ?

Well it sometime things are looks difficult when you work simple traditional way.Sometime back i was trying to submit server data from JavaScript confirm message box. I did by calling __doPostBack function in asp.net.Which looks something like this
btnSuresh.Attributes.Add("onclick", "if(!confirm('Are you sure you want to delete?')){return false;}__doPostBack();");

On other hand, It is also sometime good to overwrite override the __doPostBack function and write your own javascript code.

<script language="javascript">
var oldPostBack
function window.onload()
{
   oldPostBack = __doPostBack; 
   __doPostBack = MyFuntion;
}
function MyFuntion() 
{
    //Write you own code 
}
</script>

For More
http://www.dotnet247.com/247reference/msgs/15/77421.aspx
http://weblogs.asp.net/vga/archive/2004/03/01/NoMoreHijackingOfDoPostBackInWhidbey.aspx

Cheers..

Suresh Behera

 

1 Comment

  • You can use the following much simpler code for a confirmation:

    btnSuresh.Attributes.Add(&quot;onclick&quot;, &quot;return confirm('Are you sure you want to delete?')&quot;);

Comments have been disabled for this content.