$get() and $find() with AJAX.NET

霸气de小男生 提交于 2019-12-07 19:07:41

问题


I'm trying to follow the PageMethods example found here.
However, I get an error when trying to call $get('Label1').
Since, Label1 is an asp:Label, it works if I call $get() with the ClientID. Yet, the example is using the actual ID. Is there a way to use $get() with the actual ID?


回答1:


Well that depends what the label is contained in. In some controls it will be Label1 and work, in others it won't be. Don't chance it.

So on a simple page it gets rendered as Label1:

   <form id="form1" runat="server">
    <div>
    <asp:Label ID="Label1" Text="test" runat="server"></asp:Label>
    </div>
    </form>

On a more complex page it will be rendered as something else (ctl00_head_Label1 in my case), using a masterpage as an example:

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
 <asp:Label ID="Label1" Text="test" runat="server"></asp:Label>
</asp:Content>


来源:https://stackoverflow.com/questions/982662/get-and-find-with-ajax-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!