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
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.
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);
I was getting this when I was clicking on a LinkButton. Solved this by adding OnClick="LinkButton2_Click"
to the markup.
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...
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.
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.