如何在javascript中获取嵌入式控件的ID? [英] how to get ID of embedded control in javascript?

查看:67
本文介绍了如何在javascript中获取嵌入式控件的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有一个详细信息视图,其中包含editmode中的文本框。

如何在javascript中获取文本框的ID?

我试过这个:

< asp:DetailsView ID =" DetailsView1" RUNAT = QUOT;服务器" >

< asp:TemplateField>

< EditItemTemplate>

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

< / EditItemTemplate>

< / asp:TemplateField>

< / asp:DetailsView>


< script type =" text / javascript">

var txt = document.getElementById('' TextBox1'')

....


谢谢

Dan

解决方案

我从未使用过DetailsView控件,但是我使用了模板化的

控件,而且我有足够的ASP.NET经验来了解

生成的id几乎不是给服务器控件ID

属性的id。您将需要使用FindControl()方法和ClientID

属性。

-

Nathan Sokalski
nj ******** @ hotmail.com
http://www.nathansokalski.com/

" Dan" < nm@zszsz.xvwrote in message

news:OO ************** @ TK2MSFTNGP06.phx.gbl ...





有一个详细信息视图,其中包含editmode中的文本框。

如何获取文本框的ID在javascript中?

我试过这个:

< asp:DetailsView ID =" DetailsView1" RUNAT = QUOT;服务器" >

< asp:TemplateField>

< EditItemTemplate>

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

< / EditItemTemplate>

< / asp:TemplateField>

< / asp:DetailsView>


< script type =" text / javascript">

var txt = document.getElementById('' TextBox1'')

...


谢谢

Dan



"丹" < nm@zszsz.xvwrote in message

news:OO ************** @ TK2MSFTNGP06.phx.gbl ...


如何在JavaScript中获取TextBox的ID?



var txt = document.getElementById(''<%= TextBox1.ClientID%>'')

-

Mark Rae

ASP.NET MVP
http://www.markrae.net


感谢您的回复,

但我的代码,我得到错误:

''TextBox1''未声明''


Textbox1嵌入在detailsview1中。



Mark Rae [MVP]" < ma ** @ markNOSPAMrae.netschreef in bericht

news:uI ************** @ TK2MSFTNGP04.phx.gbl ...
< blockquote class =post_quotes>
" Dan" < nm@zszsz.xvwrote in message

news:OO ************** @ TK2MSFTNGP06.phx.gbl ...


>如何在JavaScript中获取TextBox的ID?



var txt = document.getElementById(''<%= TextBox1.ClientID%>'')


-

Mark Rae

ASP.NET MVP
http://www.markrae.net



Hi,

There is a detailsview which contains a textbox in editmode.
How to get the id of the textbox in javascript?
I tried this:
<asp:DetailsView ID="DetailsView1" runat="server" >
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</asp:DetailsView>

<script type="text/javascript">
var txt=document.getElementById(''TextBox1'')
....

Thanks
Dan

解决方案

I have never used the DetailsView control, but I have used templated
controls and I have more than enough experience with ASP.NET to know that
the generated id is almost never the one given to the server control ID
attribute. You will need to use the FindControl() method and the ClientID
property.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Dan" <nm@zszsz.xvwrote in message
news:OO**************@TK2MSFTNGP06.phx.gbl...

Hi,

There is a detailsview which contains a textbox in editmode.
How to get the id of the textbox in javascript?
I tried this:
<asp:DetailsView ID="DetailsView1" runat="server" >
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</asp:DetailsView>

<script type="text/javascript">
var txt=document.getElementById(''TextBox1'')
...

Thanks
Dan



"Dan" <nm@zszsz.xvwrote in message
news:OO**************@TK2MSFTNGP06.phx.gbl...

How to get the id of the TextBox in JavaScript?

var txt=document.getElementById(''<%=TextBox1.ClientID% >'')
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


Thanks for replying,
but with my code, i get the error:
''TextBox1'' is not declared''

Textbox1 is embedded in detailsview1.


"Mark Rae [MVP]" <ma**@markNOSPAMrae.netschreef in bericht
news:uI**************@TK2MSFTNGP04.phx.gbl...

"Dan" <nm@zszsz.xvwrote in message
news:OO**************@TK2MSFTNGP06.phx.gbl...

>How to get the id of the TextBox in JavaScript?


var txt=document.getElementById(''<%=TextBox1.ClientID% >'')
--
Mark Rae
ASP.NET MVP
http://www.markrae.net



这篇关于如何在javascript中获取嵌入式控件的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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