从 aspx 调用 ClientID

发布于 2024-08-22 19:21:51 字数 105 浏览 6 评论 0原文

"")" />

这不起作用,错误显示: 解析器错误消息:服务器标记不能包含 <% ... %>构造。

有什么办法可以解决这个问题吗? 谢谢 ;)

"")" />

that doesn't work, the error says:
Parser Error Message: Server tags cannot contain <% ... %> constructs.

Any aproaches to solve this ?
Thank you ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

以可爱出名 2024-08-29 19:21:51

您正在调用 JS 事件 (onchange),而不是服务器事件,因此只需传入 this.id 即可。

<input type="checkbox" id="chbSaveState" runat="server" tabindex="3"  
onchange="SaveState(this.id)" /> 

需要明确的是,在这种情况下,this.id<%=chbSaveState.ClientID%> 将返回相同的值。由于您是在 chbSaveState 事件上调用此函数,因此您可以在此处使用易于访问的 JS 属性,而不是 <%=chbSaveState.ClientID%>,这要求服务器返回服务器为该控件生成的 id。

You're calling a JS event (onchange), not a server event, so just pass in this.id.

<input type="checkbox" id="chbSaveState" runat="server" tabindex="3"  
onchange="SaveState(this.id)" /> 

To be clear, this.id and <%=chbSaveState.ClientID%> will return the same value in this case. Since you're calling this on an event of chbSaveState, you can just use the easily accessible JS property here, rather than <%=chbSaveState.ClientID%>, which requires the server to return the id which is generated by the server for that control.

奶茶白久 2024-08-29 19:21:51

你可以使用 jQuery 来做到这一点,如下所示:

var control = '#<%= chbSAveState.ClientID%>';
$(control).change(function(){
    SaveState($(this).id);
});

you could do that using jQuery like this:

var control = '#<%= chbSAveState.ClientID%>';
$(control).change(function(){
    SaveState($(this).id);
});
伪心 2024-08-29 19:21:51

我对服务器端控制没有太多经验,但也许:

<input type="checkbox" id="chbSaveState" runat="server" tabindex="3" 
onchange="SaveState(chbSaveState.ClientID)" />

I don't have much experience with server side controls, but perhaps:

<input type="checkbox" id="chbSaveState" runat="server" tabindex="3" 
onchange="SaveState(chbSaveState.ClientID)" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文