473,854 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to get ID of embedded control in javascript?

Dan
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:DetailsVie w ID="DetailsView 1" runat="server" >
<asp:TemplateFi eld>
<EditItemTempla te>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
</EditItemTemplat e>
</asp:TemplateFie ld>
</asp:DetailsView >

<script type="text/javascript">
var txt=document.ge tElementById('T extBox1')
....

Thanks
Dan
Oct 13 '08 #1
18 4769
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********@hotm ail.com
http://www.nathansokalski.com/

"Dan" <nm@zszsz.xvwro te in message
news:OO******** ******@TK2MSFTN GP06.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:DetailsVie w ID="DetailsView 1" runat="server" >
<asp:TemplateFi eld>
<EditItemTempla te>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
</EditItemTemplat e>
</asp:TemplateFie ld>
</asp:DetailsView >

<script type="text/javascript">
var txt=document.ge tElementById('T extBox1')
...

Thanks
Dan

Oct 13 '08 #2
"Dan" <nm@zszsz.xvwro te in message
news:OO******** ******@TK2MSFTN GP06.phx.gbl...
How to get the id of the TextBox in JavaScript?
var txt=document.ge tElementById('< %=TextBox1.Clie ntID%>')
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 13 '08 #3
Dan
Thanks for replying,
but with my code, i get the error:
'TextBox1' is not declared'

Textbox1 is embedded in detailsview1.


"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netschreef in bericht
news:uI******** ******@TK2MSFTN GP04.phx.gbl...
"Dan" <nm@zszsz.xvwro te in message
news:OO******** ******@TK2MSFTN GP06.phx.gbl...
>How to get the id of the TextBox in JavaScript?

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

Oct 14 '08 #4
When written inline into script that is generally linked to a separate file
the statement implies the <%=TextBox1.Cli entID%expressio n is parsed when
the page is compiled. Is this some kind of gift I have been ignorant of?
"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:uI******** ******@TK2MSFTN GP04.phx.gbl...
"Dan" <nm@zszsz.xvwro te in message
news:OO******** ******@TK2MSFTN GP06.phx.gbl...
>How to get the id of the TextBox in JavaScript?

var txt=document.ge tElementById('< %=TextBox1.Clie ntID%>')
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Oct 14 '08 #5
"Dan" <nm@zszsz.xvwro te in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>>How to get the id of the TextBox in JavaScript?

var txt=document.ge tElementById('< %=TextBox1.Clie ntID%>')

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

Textbox1 is embedded in detailsview1.
Well there's your problem...

JavaScript, like all languages derived from C, is case-sensitive - TextBox1
is not the same as Textbox1...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 14 '08 #6
Dan
This is my aspx code:

<asp:DetailsVie w ID="DetailsView 1" runat="server" >
<asp:TemplateFi eld>
<EditItemTempla te>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
</EditItemTemplat e>
</asp:TemplateFie ld>
</asp:DetailsView >

and javascript:

<script type="text/javascript">
var txt=document.ge tElementById('< %=TextBox1.Clie ntID%>')

With this, i get the error: 'TextBox1' is not declared' and i don't see a
difference between 'TextBox1' and 'TextBox1'.
It is surely my problem, but i post this for help. Thanks

"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netschreef in bericht
news:ue******** ******@TK2MSFTN GP03.phx.gbl...
"Dan" <nm@zszsz.xvwro te in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>>>How to get the id of the TextBox in JavaScript?

var txt=document.ge tElementById('< %=TextBox1.Clie ntID%>')

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

Textbox1 is embedded in detailsview1.

Well there's your problem...

JavaScript, like all languages derived from C, is case-sensitive -
TextBox1 is not the same as Textbox1...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 14 '08 #7
Dan
This is my aspx code:

<asp:DetailsVie w ID="DetailsView 1" runat="server" >
<asp:TemplateFi eld>
<EditItemTempla te>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
</EditItemTemplat e>
</asp:TemplateFie ld>
</asp:DetailsView >

and javascript:

<script type="text/javascript">
var txt=document.ge tElementById('< %=TextBox1.Clie ntID%>')

With this, i get the error: 'TextBox1' is not declared' and i don't see a
difference between 'TextBox1' and 'TextBox1'.
It is surely my problem, but i post this for help. Thanks
"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netschreef in bericht
news:ue******** ******@TK2MSFTN GP03.phx.gbl...
"Dan" <nm@zszsz.xvwro te in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>>>How to get the id of the TextBox in JavaScript?

var txt=document.ge tElementById('< %=TextBox1.Clie ntID%>')

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

Textbox1 is embedded in detailsview1.

Well there's your problem...

JavaScript, like all languages derived from C, is case-sensitive -
TextBox1 is not the same as Textbox1...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 14 '08 #8
"Dan" <nm@zszsz.xvwro te in message
news:eZ******** ******@TK2MSFTN GP04.phx.gbl...
This is my aspx code:

<asp:DetailsVie w ID="DetailsView 1" runat="server" >
<asp:TemplateFi eld>
<EditItemTempla te>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
</EditItemTemplat e>
</asp:TemplateFie ld>
</asp:DetailsView >

and javascript:

<script type="text/javascript">
var txt=document.ge tElementById('< %=TextBox1.Clie ntID%>')

With this, i get the error: 'TextBox1' is not declared' and i don't see a
difference between 'TextBox1' and 'TextBox1'.
It is surely my problem, but i post this for help. Thanks
Look at your previous post - you wrote:

"Textbox1 is embedded in detailsview1"

Yet the DetailsView is not called "detailsvie w1", nor does it contain a
TextBox called "Textbox1"

If you do a View Source, what is the munged name of the DetailsView and what
is the name of the munged TextBox? Please be accurate...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 14 '08 #9
Dan
in the page source, i see: 'DetailsView1_T extBox1'

var txt=document.ge tElementById('D etailsView1_Tex tBox1')

this line works. All i wanted to know is whether there was a better way
(using ClientID) to get the id. I find this method (searching in source) a
little bit too basic ..
"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netschreef in bericht
news:u1******** ******@TK2MSFTN GP02.phx.gbl...
"Dan" <nm@zszsz.xvwro te in message
news:eZ******** ******@TK2MSFTN GP04.phx.gbl...
>This is my aspx code:

<asp:DetailsVi ew ID="DetailsView 1" runat="server" >
<asp:TemplateF ield>
<EditItemTempl ate>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
</EditItemTemplat e>
</asp:TemplateFie ld>
</asp:DetailsView >

and javascript:

<script type="text/javascript">
var txt=document.ge tElementById('< %=TextBox1.Clie ntID%>')

With this, i get the error: 'TextBox1' is not declared' and i don't see a
difference between 'TextBox1' and 'TextBox1'.
It is surely my problem, but i post this for help. Thanks

Look at your previous post - you wrote:

"Textbox1 is embedded in detailsview1"

Yet the DetailsView is not called "detailsvie w1", nor does it contain a
TextBox called "Textbox1"

If you do a View Source, what is the munged name of the DetailsView and
what is the name of the munged TextBox? Please be accurate...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 14 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4124
by: rcamarda | last post by:
Beyond my control: I am finding control characters (likely tab) is making its way into address fields of our operational system. This is messing me up when I load the data into our warehouse w/ BCP (fields get shifted). Is the a nifty way to strip control characters from data? TIA Rob
0
1721
by: Kunal | last post by:
Hi all, I have run into a problem that I can't quite figure out. Here is the situation: I have to capture a signature from a WebForm. (The ASP.NET application is running on a TabletPC) Currently only an ActiveX control is available for WebForms, so I embedded it using the "<object>" tag.
0
949
by: Das | last post by:
Hi All, I have made menus in java script it works fine. but the problem is that When There is a control on the menu like combo menu goes on the back of the control, but with the text boxes it works fine. I don't know what is the problem. I want menu to be in front of any control thanks in advance.. das
1
2409
by: Slavo Smutny | last post by:
Hi, which is better approach to store my JavaScript code, to store it in separate .js file or to embed the code within HTML attributes (e.g. <p onclick="javascript:submit();">click this</p>)? I am interested in performance, i.e. how quick is page loaded in each case? I think the better one is to store the code in separate .js file so that the user browser can cache the file (source: http://www.quirksmode.org/js/placejs.html#link1) but...
1
1533
by: Simon M | last post by:
Hi, I'm not sure where to post this as it's about windows forms, web forms, socket communication and embedded objects. I am developing a smart client which is embedded in a webform. This client software communicates with a third party windows service over sockets. However I have a weird exception being raised in the AppDomain that I can't handle. When I finish the socket communication (all asyncronous) I popup a modal winform, which...
0
1175
by: Steven Spits | last post by:
Hi, I'm creating an embedded control for IE in VS 2005. For testing purpose, I have left the user control completely blank and only changed the background color. When navigating to the page containing the control, it shows up very briefly (I see a square with the selected color) but then IE crashes, giving me the "send error report to Microsoft" dialog box.
0
1185
by: idiot | last post by:
When I call PolicyHierarchy method in the IE embedded usercontrol, the html page prompt script error message "security error". It seems that there is no "SecurityException"? Html page code : <OBJECT id='Object1' height=100% width=100% classid='http:Web.MainFrame.dll#Web.MainFrame.UserControlLogin' VIEWASTEXT VIEWASTEXT>Failed </OBJECT> <script language=javascript>
3
4191
by: cfps.Christian | last post by:
I'm trying to have a javascript file included with my usercontrol, but when the page loads it says that none of my JS methods are there. What are the steps that I need to take to get a javascript file to go with the user control so that I don't have to load the script onto the page that is calling the control?
2
2156
by: Sendil kumar | last post by:
Hi All, I have embeded a data grid gontrol in IE 6. When I do an Ctrl-C on the grid control, it is not copying the values. But, right clicking on the control and select copy is working fine. Can any one tell what I need to do? Am I doing anything wrong? Thanks, Sendil
0
9750
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10672
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10362
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9509
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7909
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5738
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4147
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3181
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.