__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条回答
ら.Afraid
2楼-- · 2019-01-18 02:22

i had this error and i solved it by inserting :

<form runat="server" style="display: none"></form>
查看更多
老娘就宠你
3楼-- · 2019-01-18 02:23

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.

查看更多
我命由我不由天
4楼-- · 2019-01-18 02:28

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

查看更多
【Aperson】
5楼-- · 2019-01-18 02:30

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.

查看更多
乱世女痞
6楼-- · 2019-01-18 02:30

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.

查看更多
对你真心纯属浪费
7楼-- · 2019-01-18 02:31

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

查看更多
登录 后发表回答