Solved

Textbox Attributes.Add

Posted on 2006-07-20
4
5,823 Views
Last Modified: 2008-02-01
How do you pass a value from one text box to the other, in asp.net. I found this code  on EE. The two asp.net textboxes name's are Phone and Process_date.
Me.Process_date.Attributes.Add("onclick", "document.forms[0].Phone.value = this.value")

But the problem is when you look at the source code in IE, the name isn't Phone it is :
<input name="ctl00$ContentPlaceHolder1$Phone" type="text" id="ctl00_ContentPlaceHolder1_Phone" />

How what would the asp.net code to reference the Phone textbox?

PS I know i could use Me.Process_date.Attributes.Add("onclick", "ctl00_ContentPlaceHolder1_Phone.value = this.value") but it looks like the names are dynamic and could change. So i want to avoid doing this.
0
Comment
Question by:ocsurf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 17147415
Me.Process_date.Attributes.Add("onclick", "javascript:document.forms[0].Phone.value = " & Phone.Text & ")
0
 
LVL 1

Author Comment

by:ocsurf
ID: 17147547
no it doesn't work...because the textbox html id isn't Phone it is ctl00_ContentPlaceHolder1_Phone
0
 
LVL 14

Accepted Solution

by:
jjardine earned 250 total points
ID: 17147654
dynamically create the string for your attributes by using the clientId property like this

Me.Process_date.Attributes.Add("onclick","javascript:document.forms[0]." + Phone.ClientId + ".value = " & Phone.Text & ")  

This is assuming that your Phone textbox is named Phone.    The client id will give you the value you need.
0
 
LVL 1

Author Comment

by:ocsurf
ID: 17148356
Perfect!!
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question