__doPostBack is not defined

2019-01-18 01:46发布

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 getting that Javascript error.

i was looking in the internet and the only thing i read is that this error happends when i have a unclose tag but i review the site and its ok.

Error: __doPostBack is not defined Source File: htt://localhost:99/ProjectName/Disable.aspx Line: 1

25条回答
爷的心禁止访问
2楼-- · 2019-01-18 02:38

I had this problem just today, but none of the solutions I found worked, unfortunately including yours. So if someone reads this and it doesn't work for them try this

http://you.arenot.me/2010/11/03/asp-net-__dopostback-is-not-defined/

Cheers though for helping me through the process of working out what went wrong!

查看更多
成全新的幸福
3楼-- · 2019-01-18 02:39

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.

查看更多
Juvenile、少年°
4楼-- · 2019-01-18 02:40

Just add this code to your .aspx

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
查看更多
虎瘦雄心在
5楼-- · 2019-01-18 02:40

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

查看更多
smile是对你的礼貌
6楼-- · 2019-01-18 02:41

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.

查看更多
老娘就宠你
7楼-- · 2019-01-18 02:43

Solution for my Problem: IIS ASP.NET Webforms generates web pages depending on user Agent string

My IIS had no definition for the IE11 browser so it defaulted to a very simple browser profile which doesn't even Support JavaScript.

  • short term solution: run browser in compatibility mode.
  • medium term solution: Deployment of .Net Framework 4.5.1 which contains IE11 browser profile definitions.

An alternative: set IE11 Browser definiton file

查看更多
登录 后发表回答