473,378 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Reference a TextBox on a user control

Hi!
How do I reference let's say a button from a javascript on a user control?
The name of the button is testButton, and I've tried testButton.click() but
I get buttonTest is undefined.

Thanks!
/Henke
Nov 18 '05 #1
4 1379
When you biuld the javascript on the server side use the textButton
object's ClientID property. If you 'view source' on the page in the
browser you'll see the control has been given a prefix to make sure it
is unique.

--
Scott
http://www.OdeToCode.com

On Fri, 27 Aug 2004 13:17:39 +0200, "Henke" <he********@hotmail.com>
wrote:
Hi!
How do I reference let's say a button from a javascript on a user control?
The name of the button is testButton, and I've tried testButton.click() but
I get buttonTest is undefined.

Thanks!
/Henke


Nov 18 '05 #2
Thanks for your answer!

That looks quite uggly to me. If I move the UserControl to an other WebForm,
it wouldn't be given the same name and then the javascript wouldn't work.

/Henke

"Scott Allen" <bitmask@[nospam].fred.net> skrev i meddelandet
news:tk********************************@4ax.com...
When you biuld the javascript on the server side use the textButton
object's ClientID property. If you 'view source' on the page in the
browser you'll see the control has been given a prefix to make sure it
is unique.

--
Scott
http://www.OdeToCode.com

On Fri, 27 Aug 2004 13:17:39 +0200, "Henke" <he********@hotmail.com>
wrote:
Hi!
How do I reference let's say a button from a javascript on a user control?The name of the button is testButton, and I've tried testButton.click() butI get buttonTest is undefined.

Thanks!
/Henke

Nov 18 '05 #3
Hi Henke:

That's right - if the control moves around the ID could change.

The best way to approach this is to build the JavaScript dynamically
in your C#/VB code behind file with the ClientID property before
sending it to the client.

--
Scott
http://www.OdeToCode.com

On Fri, 27 Aug 2004 17:00:09 +0200, "Henke" <he********@hotmail.com>
wrote:
Thanks for your answer!

That looks quite uggly to me. If I move the UserControl to an other WebForm,
it wouldn't be given the same name and then the javascript wouldn't work.

/Henke

"Scott Allen" <bitmask@[nospam].fred.net> skrev i meddelandet
news:tk********************************@4ax.com.. .
When you biuld the javascript on the server side use the textButton
object's ClientID property. If you 'view source' on the page in the
browser you'll see the control has been given a prefix to make sure it
is unique.

--
Scott
http://www.OdeToCode.com

On Fri, 27 Aug 2004 13:17:39 +0200, "Henke" <he********@hotmail.com>
wrote:
>Hi!
>How do I reference let's say a button from a javascript on a usercontrol? >The name of the button is testButton, and I've tried testButton.click()but >I get buttonTest is undefined.
>
>Thanks!
>/Henke
>


Nov 18 '05 #4
That's an idea, thank you!

/Henke

"Scott Allen" <bitmask@[nospam].fred.net> skrev i meddelandet
news:u7********************************@4ax.com...
Hi Henke:

That's right - if the control moves around the ID could change.

The best way to approach this is to build the JavaScript dynamically
in your C#/VB code behind file with the ClientID property before
sending it to the client.

--
Scott
http://www.OdeToCode.com

On Fri, 27 Aug 2004 17:00:09 +0200, "Henke" <he********@hotmail.com>
wrote:
Thanks for your answer!

That looks quite uggly to me. If I move the UserControl to an other WebForm,it wouldn't be given the same name and then the javascript wouldn't work.

/Henke

"Scott Allen" <bitmask@[nospam].fred.net> skrev i meddelandet
news:tk********************************@4ax.com.. .
When you biuld the javascript on the server side use the textButton
object's ClientID property. If you 'view source' on the page in the
browser you'll see the control has been given a prefix to make sure it
is unique.

--
Scott
http://www.OdeToCode.com

On Fri, 27 Aug 2004 13:17:39 +0200, "Henke" <he********@hotmail.com>
wrote:

>Hi!
>How do I reference let's say a button from a javascript on a user

control?
>The name of the button is testButton, and I've tried
testButton.click()but
>I get buttonTest is undefined.
>
>Thanks!
>/Henke
>

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
4
by: Omar Llanos | last post by:
Recently, I posted a question on how to invoke a textbox control in Form1 (parent form) from within Form2 (which is inherited from Form1). Someone suggested to pass a reference of the Form1 to the...
0
by: Patrick | last post by:
This is a C# post. I'm using VB.NET to create an add-in for the Google Sidebar, and have implemented the OnDetailsView method. NOTE : I've come across this same problem (error message) even in...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
0
by: Dot net work | last post by:
Hi, Make up a very simple project as follows: 1 aspx form 3 web user controls (referred to as A, B, and C) "A" web user control: Put 1 textbox and 1 button on this web user control. (You...
11
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing...
14
by: 97T | last post by:
Well this is still bugging me. I know there are other ways around this, but for a number of reasons I would like to be able to do this one simple thing. I have a form with a number of controls...
1
by: aarepasky | last post by:
I list the code below, but the line that has the error is: txtCompanyName.Enabled = false; The error is: Object reference not set to an instance of an object. Default.aspx.cs using System;...
4
by: bruno | last post by:
A basic question: In a content page I access a TextBox from code behind with no problems (something like Me.MyField.Text="1"). This is the portion of aspx file : <asp:Content ID="secMessagge"...
4
by: Randy | last post by:
My situation is that I have a form on which a number of textboxes and comboboxes are added dynamically based on interaction with the user. As these controls are added, they are given names based on...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.