Javascript – __doPostBack not rendering on postback

asp.netjavascriptpostback

I'm having a strange problem.

I have to use GetPostBackEventRefence to force a Postback, but it works the first time, after the first postback, the .NET function is not rendered… any ideas?

This is what I'm missing after the postback:

<script language="javascript" type="text/javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
    var theform;
    if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
        theform = document.Main;
    }
    else {
        theform = document.forms["Main"];
    }
    theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
    theform.__EVENTARGUMENT.value = eventArgument;
    theform.submit();
}
// -->
</script>

Best Answer

The first thing I would look at is whether you have any asp controls (such as linkbutton, comboboxes,that don't normally generate a submit but requre a postback) being displayed on the page. The __doPostback function will only be put into the page if ASP thinks that one of your controls requires it.

If you aren't using one of those you can use:

Page.ClientScript.GetPostBackClientHyperlink(controlName, "")

to add the function to your page