在Asp.Net 2中重命名控件 [英] Renaming of controls in Asp.Net 2

查看:43
本文介绍了在Asp.Net 2中重命名控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用客户端脚本来启用/禁用按钮

(取决于其他字段中的值)。这在Asp.Net 1.1中运行良好,但是在Asp.Net 2.0中是

,所有名称和web和html控件的id都是

修改,例如:


< asp:Button Runat =" server" ID = QUOT; modifyCtrl"文本= QUOT;修改" / ASP:按钮>是

生成为

< input type =" submit"命名= QUOT; ctl00 $ $主&modifyCtrl QUOT; value =" Modify"

id =" ctl00_main_modifyCtrl" />


如果Asp.Net 2.0修改了

ID和名称,我的客户端脚本如何禁用我的按钮?有没有一种我可以调用的方法可以转换我的客户端

脚本,这样如果Asp.Net更改了

未来版本中的命名约定,它们就不会中断(例如作为RegisterClientScriptBlock())?


C.Levasseur

解决方案

main

modifyCtrl" value =" Modify"

id =" ctl00_main_modifyCtrl" />


如果Asp.Net 2.0修改了

ID和名称,我的客户端脚本如何禁用我的按钮?有没有一种我可以调用的方法可以转换我的客户端

脚本,这样如果Asp.Net更改了

未来版本中的命名约定,它们就不会中断(例如作为RegisterClientScriptBlock())?


C.Levasseur


有人打破你的JavaScript版本,所以getElementById()停止了

工作吗?

他们删除了split()函数还是什么?不支持

数组?


试一试。在您将getElementById返回的结果分成

后,控件的名称将在数组中。不要硬编码对

的任何引用分配给控制树的任何值,因为对页面的任何更改将导致不同的控制树,事实上对运行时任何

控件的任何更改都可以并且将从树中删除它们,它仍然可以在客户端和服务器上进行
对应。如果您的客户端脚本设计得很好,那么您的代码应该活到成熟的年代。好吧,至少直到

3.0发布:-)


<%= Clinton Gallagher

METROmilwaukee(sm)" ;区域信息服务

NET csgallagher AT metromilwaukee.com

URL http://metromilwaukee.com/

网址 http://clintongallagher.metromilwaukee.com/



C。莱维塞尔" < CL ******** @ newsgroup.nospam>在留言中写道

新闻:eq ************* @tk2msftngp13.phx.gbl ...

我想用客户端启用/禁用按钮的辅助脚本
(取决于其他字段中的值)。这在Asp.Net 1.1中运行良好,但在Asp.Net 2.0中,所有名称和web和HTML控件的id都被修改,例如:

< asp:Button Runat =" server" ID = QUOT; modifyCtrl"文本= QUOT;修改" / ASP:按钮>生成为
< input type =" submit"名称= QUOT; ctl00

I would like to use client side scripting for enabling/disabling buttons
(depending on values in other fields). This worked fine in Asp.Net 1.1 but
in Asp.Net 2.0, all the names and the id''s of the web and html controls are
modified, for example:

<asp:Button Runat="server" ID="modifyCtrl" Text="Modify" /asp:Button> is
generated as
<input type="submit" name="ctl00$main$modifyCtrl" value="Modify"
id="ctl00_main_modifyCtrl" />

How can my client side scripts disable my button if Asp.Net 2.0 modifies the
ID''s and the names? Is there a method I can call that will convert my client
scripts so they won''t break if Asp.Net changes the naming convention in a
future version (such as RegisterClientScriptBlock() )?

C.Levasseur

解决方案

main


modifyCtrl" value="Modify"
id="ctl00_main_modifyCtrl" />

How can my client side scripts disable my button if Asp.Net 2.0 modifies the
ID''s and the names? Is there a method I can call that will convert my client
scripts so they won''t break if Asp.Net changes the naming convention in a
future version (such as RegisterClientScriptBlock() )?

C.Levasseur


Did somebody break your version of JavaScript so getElementById( ) stopped
working?
Did they remove the split( ) function or something? Not include support for
arrays?

Try it out. The name of your control will be in the array after you split
the results returned by getElementById. Don''t hard-code any references to
any value assigned to the control tree as any change to your page will
result in a differently ordered control tree and in fact any changes to any
controls at run-time can and will remove them from the tree which remains
adressable on both the client and the server. If your client-side script is
designed well your code should live to a ripe old age. Well, at least until
3.0 is released :-)

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/



"C. Levasseur" <cl********@newsgroup.nospam> wrote in message
news:eq*************@tk2msftngp13.phx.gbl...

I would like to use client side scripting for enabling/disabling buttons
(depending on values in other fields). This worked fine in Asp.Net 1.1 but
in Asp.Net 2.0, all the names and the id''s of the web and html controls are
modified, for example:

<asp:Button Runat="server" ID="modifyCtrl" Text="Modify" /asp:Button> is
generated as
<input type="submit" name="ctl00


这篇关于在Asp.Net 2中重命名控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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