__doPostBack is not defined

后端 未结 26 2189
不知归路
不知归路 2020-12-09 08:12

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

26条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 08:47

    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.

提交回复
热议问题