Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__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

like image 918
jmpena Avatar asked Aug 13 '10 20:08

jmpena


4 Answers

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);
like image 146
Don Tato Avatar answered Oct 22 '22 02:10

Don Tato


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.

like image 20
SAGExSDX Avatar answered Oct 22 '22 03:10

SAGExSDX


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.

like image 16
Paul Keister Avatar answered Oct 22 '22 02:10

Paul Keister


Just add this code to your .aspx

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
like image 15
Jose Luis Avatar answered Oct 22 '22 02:10

Jose Luis