ASCX 文件中的 ClientID [英] ClientID inside of ASCX file

查看:14
本文介绍了ASCX 文件中的 ClientID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

虽然这个

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

呈现为我的 id 是: fracTemplateCtrl

renders as My id is: fracTemplateCtrl

这个:

        <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('&lt;%=this.ClientID%>');" id="fracTemplateCtrl_btnSave" />

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

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)

推荐答案

您可以像这样在服务器端设置 OnClientClick 属性的值:

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

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

这篇关于ASCX 文件中的 ClientID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆