0Day Forums
__doPostBack is not defined - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: Asp.Net (https://0day.red/Forum-Asp-Net)
+--- Thread: __doPostBack is not defined (/Thread-doPostBack-is-not-defined)

Pages: 1 2 3


__doPostBack is not defined - providing377200 - 07-23-2023

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 <script> tag but i review the site and its ok.


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


RE: __doPostBack is not defined - rumbullion140341 - 07-23-2023

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



RE: __doPostBack is not defined - vendition822740 - 07-23-2023

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


[1]:

[To see links please register here]




RE: __doPostBack is not defined - seng415 - 07-23-2023

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

[

[To see links please register here]

][1]

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


[1]:

[To see links please register here]




RE: __doPostBack is not defined - Mrnonvariation262 - 07-23-2023

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.


RE: __doPostBack is not defined - serpent785 - 07-23-2023

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][1] 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.

[1]:

[To see links please register here]




RE: __doPostBack is not defined - jacquettacexyrdhp - 07-23-2023

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.


RE: __doPostBack is not defined - olibanum117384 - 07-23-2023

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!


RE: __doPostBack is not defined - cheex - 07-23-2023

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!


RE: __doPostBack is not defined - lave376495 - 07-23-2023

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