Solved

Textbox Attributes.Add

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

717 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