?
Solved

Textbox Attributes.Add

Posted on 2006-07-20
4
Medium Priority
?
5,842 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

650 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