ASP.NET Javascript '__doPostBack' is undefined

function my_page_start_onload() {
    if (__doPostBack) { //  Error: '__doPostBack' is undefined
        ...
    }
}
window.onload = my_page_start_onload();

I have tried many ways but with no luck.

  1. Control Panel -> Windows Update -> is up-to-date -> still error
  2. Browser Definition Updated (aspnet_regiis.exe -i and iisreset) -> see http://forum.jdp.tw/thread-1552-1-1.html -> Added browser definition to C:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG\Browsers\ie.browsers -> RUN C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_regbrowsers.exe -i -> RUN iisreset -> still error

  3. Try to install hotfix, but occurs an error The update is not applicable to your computer

  4. Try to install .NET Framework, but occurs an error The update is not applicable to your computer

  5. VS2012 with .NET 4.5 to run this function with blank page, still error

  6. All versions of IE5-11, still error

Remarks:

  1. Request.Browser.Browser returns InternetExplorer
  2. Request.Browser.Version returns 11.0

Computer Environment

  1. windows 7 64-bit
  2. VS2008 with .NET 3.5
  3. IIS 7.5' application pool use .NET v2.0 version
  4. IE11.

Many thanks for help!

Answers


Postback function will be automatically generated for you by .NET if your page contains some control that requires postback, but don't normally cause postback. Consider a submit button - it causes postack, but don't need additional js code because it's designed to cause postback. However, controls like linkbutton (rendered as anchor) or dropdownlist don't normally cause postback that's why asp.net will generate __postback function for them. So in order to force asp.net to generate _postback function you can add to page some dummy control or you can make <form> tag runat=server or if you want to include __postback function in every page no matter what controls they contrains you can execute this function in your master page Page_Load event:

ClientScript.GetPostBackEventReference(this, "");

Need Your Help

Set current date based on selection form ComboBox using WPF and MVVM

wpf mvvm

I am trying to figure out a way to get the current date and set that value to "Completed On" only when Status is set to "Inactive if Status is set to "Active" then i want Completed On to be empty. ...

Understanding MVC: Whats the concept of "Fat" on models, "Skinny" on controllers?

php model-view-controller paradigms

I'm trying to understand the concept of "Fat" on models vs "skinny" on controllers and from what I've been discussing I have the following example (this is taken from a freenode discussion):