框架生成的ID困境 [英] Framework-generated ID woes

查看:52
本文介绍了框架生成的ID困境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我的ASP.NET 2.0页面上有很多控件,有些实现了

INamingContainer,其他只是< asp:button> s等等。


永恒的哀叹:我需要在

客户端与这些控件进行交互,但当然我无法保证由框架生成的ID将是一致的(例如

" ctl00_ContentPlaceHolder_LoadPreviousButton")。


有没有办法告诉框架你想要使用什么前缀

你的控件的ID?或者我是否必须在页面中注入一些包含ID的JavaScript

(我觉得这很难看)。如果是这样,

我如何获得控件的完全限定名称?


谢谢,Mark

Hi

I have lots of controls on my ASP.NET 2.0 page, some implementing
INamingContainer, others just <asp:button>s and so on.

The eternal lament: I need to interact with these controls on the
client-side, but of course I can''t guarantee that the IDs generated by
the Framework will be consistent (like
"ctl00_ContentPlaceHolder_LoadPreviousButton") .

Is there a way to tell the Framework what prefix you''d like to use for
your controls'' IDs? Or do I have to resort to injecting some JavaScript
containing the ID into the page (which is rather ugly I think). If so,
how do I actually get the fully-qualified name of the control?

Thanks, Mark

推荐答案

component.ClientID


:-)

喜欢:


document.getElementById(''<%= myLabel.ClientID%>'')。value =''test'';


- -


Bruno Alexandre

(葡萄牙人在K?benhanv,Danmark)

< ma ****** ****@gmail.com> escreveu na mensagem

news:11 ********************* @ y41g2000cwy.googlegro ups.com ...
component.ClientID

:-)

like:

document.getElementById( ''<%= myLabel.ClientID %>'' ).value = ''test'';

--

Bruno Alexandre
(a Portuguese in K?benhanv, Danmark)
<ma**********@gmail.com> escreveu na mensagem
news:11*********************@y41g2000cwy.googlegro ups.com...


我的ASP.NET 2.0页面上有很多控件,有些实现了INamingContainer,有些只是< asp:button> s等等。

永恒的哀叹:我需要在客户端与这些控件进行交互,但当然我不能保证框架生成的ID会保持一致(比如
" ctl00_ContentPlaceHolder_LoadPreviousButton")。

有没有办法告诉框架你想用什么前缀来控制你的控件的ID?或者我是否必须在页面中注入一些包含ID的JavaScript(我觉得这很丑陋)。如果是这样,
如何获得控件的完全限定名称?

谢谢,Mark
Hi

I have lots of controls on my ASP.NET 2.0 page, some implementing
INamingContainer, others just <asp:button>s and so on.

The eternal lament: I need to interact with these controls on the
client-side, but of course I can''t guarantee that the IDs generated by
the Framework will be consistent (like
"ctl00_ContentPlaceHolder_LoadPreviousButton") .

Is there a way to tell the Framework what prefix you''d like to use for
your controls'' IDs? Or do I have to resort to injecting some JavaScript
containing the ID into the page (which is rather ugly I think). If so,
how do I actually get the fully-qualified name of the control?

Thanks, Mark



Darn it。无法指定ID前缀?似乎有危险的修改

这个ClientID属性(如果这甚至可能,看起来都没有......)


Mark


Bruno Alexandre写道:
Darn it. No way to specify the ID prefix? Seems dangerous to modify
this ClientID property (if that''s even possible, haven''t looked...)

Mark

Bruno Alexandre wrote:
component.ClientID

:-)

喜欢:

document.getElementById(''<%= myLabel.ClientID%>'')。value =''test'';

-

Bruno Alexandre
(葡萄牙人在K?benhanv,丹麦)

< ma ********** @ gmail.com> escreveu na mensagem
新闻:11 ********************* @ y41g2000cwy.googlegro ups.com ...
component.ClientID

:-)

like:

document.getElementById( ''<%= myLabel.ClientID %>'' ).value = ''test'';

--

Bruno Alexandre
(a Portuguese in K?benhanv, Danmark)
<ma**********@gmail.com> escreveu na mensagem
news:11*********************@y41g2000cwy.googlegro ups.com...
你好

我的ASP.NET 2.0页面上有很多控件,有些实现了INamingContainer,有些只是< asp:button> s等等。

永恒的哀叹:我需要在客户端与这些控件进行交互,但当然我不能保证框架生成的ID是一致的(比如
) " ctl00_ContentPlaceHolder_LoadPreviousButton")。

有没有办法告诉框架你想用什么前缀来控制你的控件的ID?或者我是否必须在页面中注入一些包含ID的JavaScript(我觉得这很丑陋)。如果是这样,
如何获得控件的完全限定名称?

谢谢,Mark
Hi

I have lots of controls on my ASP.NET 2.0 page, some implementing
INamingContainer, others just <asp:button>s and so on.

The eternal lament: I need to interact with these controls on the
client-side, but of course I can''t guarantee that the IDs generated by
the Framework will be consistent (like
"ctl00_ContentPlaceHolder_LoadPreviousButton") .

Is there a way to tell the Framework what prefix you''d like to use for
your controls'' IDs? Or do I have to resort to injecting some JavaScript
containing the ID into the page (which is rather ugly I think). If so,
how do I actually get the fully-qualified name of the control?

Thanks, Mark






with


document.getElementById(''<%= myLabel.ClientID%>'')。value =''test'';


你没有修改任何东西!只需读取指定

标签的ClientID。

页面上面的代码将呈现为:


document.getElementById (''ctl00_mainCHolder_myLabel'')。value =''test'';


如果你在名为mainCHolder的容器中有Label,想象一下你是否有
容器内的标签和向导组件...


所有你需要担心的是提升myLabel.ClientID


ClientID as你可以看到ReadOnly ....你什么都不能改变,我们只需要

来阅读它!


我真的不会知道你在哪里有改变它的想法!


-


Bruno Alexandre

(葡萄牙语在K?benhanv,Danmark)

< ma ********** @ gmail.com> escreveu na mensagem

新闻:11 ********************** @ p79g2000cwp.googlegr oups.com ......

Darn it。无法指定ID前缀?似乎有危险的修改

这个ClientID属性(如果这甚至可能,看起来都没有......)


Mark


Bruno Alexandre写道:
with

document.getElementById( ''<%= myLabel.ClientID %>'' ).value = ''test'';

you are not modifing anything!!! just READING the ClientID for the specified
tag.
in the page the code above will render as:

document.getElementById( ''ctl00_mainCHolder_myLabel'' ).value = ''test'';

if you have the Label in a container called mainCHolder, imagine if you have
the label inside a container and a wizard component...

all you need to worry is to mension myLabel.ClientID

ClientID as u can see is ReadOnly.... you can''t alter nothing, we just need
to read it!

I really don''t know where do you get the idea for change it!

--

Bruno Alexandre
(a Portuguese in K?benhanv, Danmark)
<ma**********@gmail.com> escreveu na mensagem
news:11**********************@p79g2000cwp.googlegr oups.com...
Darn it. No way to specify the ID prefix? Seems dangerous to modify
this ClientID property (if that''s even possible, haven''t looked...)

Mark

Bruno Alexandre wrote:
component.ClientID

:-)

喜欢:

document.getElementById(''<%= myLabel.ClientID%>'')。value =''test'';

-

Bruno Alexandre
(葡萄牙人在K?benhanv,丹麦)

< ma ********** @ gmail.com> escreveu na mensagem
新闻:11 ********************* @ y41g2000cwy.googlegro ups.com ...
component.ClientID

:-)

like:

document.getElementById( ''<%= myLabel.ClientID %>'' ).value = ''test'';

--

Bruno Alexandre
(a Portuguese in K?benhanv, Danmark)
<ma**********@gmail.com> escreveu na mensagem
news:11*********************@y41g2000cwy.googlegro ups.com...
你好

我的ASP.NET 2.0页面上有很多控件,有些实现了INamingContainer,有些只是< asp:button> s等等。

永恒的哀叹:我需要在客户端与这些控件进行交互,但当然我不能保证框架生成的ID是一致的(比如
) " ctl00_ContentPlaceHolder_LoadPreviousButton")。

有没有办法告诉框架你想用什么前缀来控制你的控件的ID?或者我是否必须在页面中注入一些包含ID的JavaScript(我觉得这很丑陋)。如果是这样,
如何获得控件的完全限定名称?

谢谢,Mark
Hi

I have lots of controls on my ASP.NET 2.0 page, some implementing
INamingContainer, others just <asp:button>s and so on.

The eternal lament: I need to interact with these controls on the
client-side, but of course I can''t guarantee that the IDs generated by
the Framework will be consistent (like
"ctl00_ContentPlaceHolder_LoadPreviousButton") .

Is there a way to tell the Framework what prefix you''d like to use for
your controls'' IDs? Or do I have to resort to injecting some JavaScript
containing the ID into the page (which is rather ugly I think). If so,
how do I actually get the fully-qualified name of the control?

Thanks, Mark



这篇关于框架生成的ID困境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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