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 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 

For More


Suresh Behera



  • 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;);

  • And build on fabrice's idea and create your own DeleteButton control which inherits from Button and does just that.

  • To override a function in javascript, just rewrite the function beneath it. Javascript won't complain about two signatures being the same and the last one in always wins. And no, its not anomaly. Its designed that way.

    If you call the init function below you will always see the message &quot;2&quot;.

    function init(){



    function init(){



  • Ok Dave, but how do you call the first init from the second?

Comments have been disabled for this content.