有没有一种方法可以防止ASP.Net破坏控件ID? [英] Is there a way to keep ASP.Net from mangling control IDs?

查看:95
本文介绍了有没有一种方法可以防止ASP.Net破坏控件ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控件:

I have a control:

<asp:TextBox ID="ControlName" runat="server" />



我想在一些Javascript中引用它.

ASP.Net将ID修改为ctl00_ContentPlaceHolder1_ControlName.
为了简单起见,我想在脚本中将其称为ControlName:页面的未来版本可能会将控件放在不同的容器中,这会更改ID,并且我宁愿不必记住重写脚本.



I want to reference it in some Javascript.

ASP.Net mangles the ID into ctl00_ContentPlaceHolder1_ControlName.
To keep things simple I want to refer to it as ControlName in my script: future versions of the page might have the control in a different container which would alter the ID, and I would rather not have to remember to rewrite the script.

Is there any way to instruct ASP.Net, either for this specific control or generally, NOT to mangle the ID?

推荐答案

这是什么?之所以发生这种情况,是因为您使用的是母版页.检查以下内容:

http: //weblogs.asp.net/scottgu/archive/2006/04/18/Great-New-Advanced-Article-on-ASP.NET-2.0-Master-Pages.aspx [
It''s happening because you''re using a master page. Check this:

http://weblogs.asp.net/scottgu/archive/2006/04/18/Great-New-Advanced-Article-on-ASP.NET-2.0-Master-Pages.aspx[^]


这篇关于有没有一种方法可以防止ASP.Net破坏控件ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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