ViewState with example in asp.net C#

Saturday, January 8, 2011

_doPostBack() in javascript in asp.net

Calling postback event from Javascript



There may be some scenario where you may want to explicitly postback to the server using some clientside javascript. It is pretty simple to do this.

ASP.NET already creates a client side javascript method as shown below to support Postbacks for the web controls:

function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}


So, all you have to do is, just call this method with appropriate arguments. You may call this as shown below:

<script language='Javascript'>
__doPostBack('__Page', 'MyCustomArgument');
</script>

No comments:

Post a Comment