Solved

Textbox Attributes.Add

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now