Solved

Textbox Attributes.Add

Posted on 2006-07-20
4
5,816 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
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

821 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