473,383 Members | 1,997 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,383 software developers and data experts.

Referencing a control in Javascript

Hi all,

In my code-behind, I validate some controls and if a particular control has
a problem, I not only send an alert down to the client via
Page.RegisterStartupScript but I'd like to set the focus of the control. now
the control in question is embedded into a user control which is, in turn,
embedded into a user control which, in turn, is embedded onto a web form.

The Javascript does not work if I when I refernce the control with it's ID.
I checked the client source and saw it was renamed to
'_ctl2_UCIngDetail_lstUnits2'. Now when I changed the Javascript to
'document.frmMain._ctl2_UCIngDetail_lstUnits2.focu s();', this worked. but
isn't this going to break if controls are added to the usercontrol?

What is the correct way to solve this dilemma?

Regards
John.
Nov 17 '05 #1
2 3625
You will need to use the "ClientID" property of the control to reference it
properly.
"John" <a@b.com> wrote in message
news:#U**************@TK2MSFTNGP10.phx.gbl...
Hi all,

In my code-behind, I validate some controls and if a particular control has a problem, I not only send an alert down to the client via
Page.RegisterStartupScript but I'd like to set the focus of the control. now the control in question is embedded into a user control which is, in turn,
embedded into a user control which, in turn, is embedded onto a web form.

The Javascript does not work if I when I refernce the control with it's ID. I checked the client source and saw it was renamed to
'_ctl2_UCIngDetail_lstUnits2'. Now when I changed the Javascript to
'document.frmMain._ctl2_UCIngDetail_lstUnits2.focu s();', this worked. but
isn't this going to break if controls are added to the usercontrol?

What is the correct way to solve this dilemma?

Regards
John.

Nov 17 '05 #2
js ="<script ...>" & txtBox.ClientID & ".focus();</scirpt>"
"John" <a@b.com> wrote in message
news:#U**************@TK2MSFTNGP10.phx.gbl...
Hi all,

In my code-behind, I validate some controls and if a particular control has a problem, I not only send an alert down to the client via
Page.RegisterStartupScript but I'd like to set the focus of the control. now the control in question is embedded into a user control which is, in turn,
embedded into a user control which, in turn, is embedded onto a web form.

The Javascript does not work if I when I refernce the control with it's ID. I checked the client source and saw it was renamed to
'_ctl2_UCIngDetail_lstUnits2'. Now when I changed the Javascript to
'document.frmMain._ctl2_UCIngDetail_lstUnits2.focu s();', this worked. but
isn't this going to break if controls are added to the usercontrol?

What is the correct way to solve this dilemma?

Regards
John.

Nov 17 '05 #3

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

Similar topics

10
by: Data Guy | last post by:
In my approach to validation for widgets, i write javascript functions. At the end of the document, inside the form, i invoke the function as <FORM NAME="testit"> <INPUT TYPE="TEXT" VALUE="2"...
1
by: Dune | last post by:
Saw a post a about hiding a panel using javascript a while back and that got me curious and i tried it out. I have a Panel control with id equal to PanelId and it is nested inside a form tag...
1
by: Martin | last post by:
Hello Group I'm having a bit of trouble figuring this out. I'm grateful for any hints. Let's assume I'm have a webapplication with two .aspx pages, Page A and Page B. Page A consists of a...
3
by: Lyners | last post by:
I have a table within a cell of a datagrid. I am doing updates without postback to the server using Javascript. I have everything working, except referencing a table within the datagrid cell. ...
3
by: gary | last post by:
Hi, I am trying to reference an anchor in a user control with a url. This worked in 1.1 but no longer works in 2.0. The ascx control is located in a "/include" folder If you have a...
1
by: WB | last post by:
Hi, I would like to do something like this page: http://www.stocklayouts.com/Products/Postcard/Postcard-Template-Design-Library.aspx?kwid=38 Notice when you mouse-over any of the icons under...
21
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
3
by: DanG | last post by:
Hi I used to have an ImageButton in my datagrid, and referenced the control in the javascript with: var fld = document.getElementById('datagrid__ctl2_btnEdit'); alert(fld); //returns "" >Good...
2
by: HockeyFan | last post by:
Yesterday, I posted a question dealing with an issue of trying to reference (from javascript on the client side) an item within a Repeater. My code was hard-coded to use the actual ClientId, but...
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
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.