ASCX 文件内的 ClientID

发布于 2024-07-15 02:33:43 字数 667 浏览 6 评论 0原文

我正在尝试获取 .ascx(用户控制标记)文件中的 CLientID。

虽然这

My id is: <%=this.ClientID%>

呈现为 我的 id 是: fracTemplateCtrl

这:

        <asp:Button ID="btnSave" runat="server" Text="Save Template" onclick="btnSave_Click" OnClientClick="return confirmSave('<%=this.ClientID%>');" />

呈现为(在源代码内):

        <input type="submit" name="fracTemplateCtrl$btnSave" value="Save Template" onclick="return confirmSave('&lt;%=this.ClientID%>');" id="fracTemplateCtrl_btnSave" />

显然,在第二种情况下不会评估 ClientId 属性。 我该如何克服这个问题? (除了硬编码,这不是答案,我想让用户控件独立)

I am trying to get CLientID inside the .ascx (user control mark-up) file.

While this

My id is: <%=this.ClientID%>

renders as
My id is: fracTemplateCtrl

This:

        <asp:Button ID="btnSave" runat="server" Text="Save Template" onclick="btnSave_Click" OnClientClick="return confirmSave('<%=this.ClientID%>');" />

renders as (inside Source code):

        <input type="submit" name="fracTemplateCtrl$btnSave" value="Save Template" onclick="return confirmSave('<%=this.ClientID%>');" id="fracTemplateCtrl_btnSave" />

Clearly, ClientId property does not get evaluated in the second case. How do I overcome this issue? (aside from hardcoding, which is not the answer, I would like to make the user control independent)

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

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

发布评论

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

评论(2

热鲨 2024-07-22 02:33:43

您可以在服务器端设置 OnClientClick 属性的值,如下所示:

btnSave.OnClientClick = "return confirmSave('" + this.ClientID + "')";

You could set the OnClientClick property's value server-side like this:

btnSave.OnClientClick = "return confirmSave('" + this.ClientID + "')";
稀香 2024-07-22 02:33:43

试试这个

<asp:Button ID="btnSave" runat="server" Text="Save Template" onclick="btnSave_Click" OnClientClick="return confirmSave(this.id);" /> 

Try this instead

<asp:Button ID="btnSave" runat="server" Text="Save Template" onclick="btnSave_Click" OnClientClick="return confirmSave(this.id);" /> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文