__doPostBack is not defined

后端 未结 26 2036
不知归路
不知归路 2020-12-09 08:12

Im getting that error when try to call a __doPostBack on one of my pages, every page that i have in the project use __doPostBack function but in this particular page im gett

相关标签:
26条回答
  • 2020-12-09 08:24

    For me it was the fact that I was using a custom User-Agent Header of User-Agent: This is a Test, please ignore.

    This is because IIS ASP.NET Webforms generates web pages depending on the User-Agent string.

    To fix it, I included the browser types, plus a message at the end, i.e.

    User-Agent: Mozilla/5.0 (X11; Linux x86_64) Chrome/75.0.3770.80 (This is a Test, please ignore)
    

    And the page started running correctly again.

    0 讨论(0)
  • 2020-12-09 08:26

    The run time/client side error __doPostBack is undefined hassled me for a few hours. There was lots of misleading/incorrect help on the net. I inserted the following line of code in the Page_Load event of the default.aspx.cs file and everything worked fine, on my system and in production with GoDaddy.

    ClientScript.GetPostBackEventReference(this, string.Empty);
    
    0 讨论(0)
  • 2020-12-09 08:26

    I was getting this when I was clicking on a LinkButton. Solved this by adding OnClick="LinkButton2_Click" to the markup.

    0 讨论(0)
  • 2020-12-09 08:26

    Old question but recent answer: if you have a ScriptManager, check if EnablePartialRendering is enabled. If so, disable it, I don't know why it's a problem there...

    0 讨论(0)
  • 2020-12-09 08:26

    For me "__doPostBack" did not work in all pages because I compiled my project with newer version of Visual stdio then I double clicked on properties in solution explorer and changed "Target framework " from .Net framework 4.0 to .Net framework 3.0 and after that rebuild project and it worked.

    0 讨论(0)
  • 2020-12-09 08:27

    Essentially what's going on is that there are 2 missing html hidden elements "eventtarget" and "eventargument", as well as a missing function "__doPostBack".

    These are missing from the DOM.

    I tried all the fixes listed for this and none worked. However using a combination of jquery and javascript there is an unobtrusive solution. Add this to your javascript on document ready and you're off to the races (This is a much quicker alternative than installing the .net framework 4.5 on your server, although if you can install 4.5 thats the way to go):

    if ($('#__EVENTTARGET').length <= 0 && $('#__EVENTARGUMENT').length <= 0) {
      $('#YOUR_ASPNET_FORMID').prepend('<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /><input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />');
    }
    
    if (typeof __doPostBack == 'undefined') {
      __doPostBack = function (eventTarget, eventArgument) { object
        var theForm = document.forms['YOUR_ASPNET_FORMID'];
        if (!theForm) {
          theForm = document.YOUR_ASPNET_FORMID;
        }
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
          theForm.__EVENTTARGET.value = eventTarget;
          theForm.__EVENTARGUMENT.value = eventArgument;
          theForm.submit();
        }
      };
    }
    

    I understand that some of said installing 4.5 fixes this. I would definitely recommend that. However, if you're like me working on an enterprise public facing site with a cms system baked in .net 4, this might just be an easier solution, as opposed to possibly introducing new bugs created from updating your platform.

    0 讨论(0)
提交回复
热议问题