__doPostBack is not defined

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


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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);

Method 2

If the page doesn’t have a control that causes a postback, __doPostBack() won’t be output as a function definition. One way to override this is to include this line in your Page_PreRender():

this.Page.ClientScript.GetPostBackEventReference(<a control>, string.Empty);

This function returns a string calling __doPostBack(); but also forces the page to output the __doPostBack() function definition.

Method 3

Here’s why this was happening to me: I accidentally forgot that script tags must always have closing tags:

<script src="/Scripts/appLogic/Regions.js" />

I corrected the script tag:
<script src="/Scripts/appLogic/Regions.js" type="text/javascript" ></script>

and sanity returned.

Method 4

Just add this code to your .aspx

<asp:ScriptManager ID="ScriptManager1" runat="server">

Method 5

__doPostBack() should be automatically included by any ASP.NET WebControl that could cause a post back. You sound like you are calling it manually in some Javascript you wrote. If so, you will need to include a WebControl, to make sure that function in inserted onto the page.

Method 6

__doPostBack Works guys

Write this code in Page Load

ClientScript.GetPostBackEventReference(this, “”);

Method 7

Try calling the RegisterRequiresPostBack method. It should make the ASP.NET runtime include the __doPostBack code.

Method 8

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;

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.

Method 9

I had this problem when I wrote my own page code and forgot to put runat="server" on the form element.

Method 10

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

Method 11

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.

Method 12

I know it’s been a while since this thread was active, but I’ll add another tidbit for those coming along in the future.

The ClientScriptManager class has available a couple of methods that make dealing with JavaScript postbacks better. In particular is the GetPostBackClientHyperlink routine. It retuns a string that you can then just assign to the element’s onclick client-side event. Any time you use this method the __doPostBack routine and any necessary hidden form fields are automatically generated, plus you don’t have to write the JavaScript yourself. For example, I have this in the Page_Load:

lnkDeactivate.Attributes("onclick") = ClientScript.GetPostbackClientHyperlink(lnkDeactivate, "deactivate")

In this case, ClientScript is the ClientScriptManager object instance automatically made available by the page…I did not instantiate it. On the post-back, I use this code to detect the event:
If Not String.IsNullOrEmpty(Request("__EVENTARGUMENT")) AndAlso Request("__EVENTARGUMENT") = "deactivate") Then
  '-- do somthing
End If

I’m sure there are better/cleaner ways to hook this up, but I hope you get the idea behind it.

Method 13

 this.Page.ClientScript.GetPostBackEventReference(<a control>, string.Empty);

This trick worked for me. Still would have liked to know why it wasn’t rendering…

Thank you!

Method 14

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


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

Method 15

I was getting this because my script was inside an Iframe that was being “disposed” (it was a Telerik “window” that was closed). The code defining _dopostback() inside my iframe was gone, but the code calling _dopostback() inside my iframe was still hanging around. Love that JavaScript!

Method 16

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

Method 17

Another addition to this vintage thread….

I had these symptoms while developing a site using JQuery Mobile, and it turned out that it was caused by the link I followed to the affected page not having the rel="external" attribute set on it.

This meant that JQuery loaded the contents of the new page via AJAX, and ‘injected’ them into the current page, rather than reloading the whole thing, and hence the required postback javascript wasn’t present until a full page refresh.

Method 18

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…

Method 19

I had this problem and sometimes its just stupidity. I wrote it as __doPostback with a lowercase’b’, where it should have been __doPostBack with an uppercase ‘B’.

Method 20

i used this method in my script that included to asp.net form:

main form id sample:
<script src="myscript" />

<form id="frmPost" runat="server">

// myscript.js in java script function
mypostboack: function () {

Method 21

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.

Method 22

i had this error and i solved it by inserting :

<form runat="server" style="display: none"></form>

Method 23

lnkDeactivate.Attributes("onclick") = ClientScript.GetPostbackClientHyperlink(lnkDeactivate, "deactivate")

Method 24

Wrapping my server side controls in a form element with runat="server" attribute worked for me. According to asp environment there should be only one form element with runat="server" attribute in it otherwise some serious issue may happen.

<form runat="server" id="form1">
   <!-- Server side controls go here -->

Method 25

It is __doPostBack function not found error. Put one button in page and set its usersubmitbehavior=false, then run and see viewsource, you will have __doPostBack function automatically be added in your page.

Now put your own html button which you want to make postback from and call __doPostBack function by setting its onclick=”__doPostBack(‘mybut’,’save’)”.

Now the __doPostBack function required for your html button is given by the above button.

Method 26

For me it was the following was missing from the page:

<form runat="server">

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x