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

Accessing HTML Control in ASCX through JavaScript

I have a JavaScript called common.js that is referenced by every ASPX in my
web application. In common.js, I have a funtion called findText (which I use
to help me navigate through drop down lists by typing the first few letters
of an item in the drop down list).

So this is how I would use it:

<input type="text" id="searchCompany" size="1" name="searchCompany"
onkeyup="findText(this, Company);">
<asp:dropdownlist ID="Company" Runat="server"></asp:dropdownlist>

All this is fine on a normal webform. But I run into trouble when my
dropdown list is inside a user control. Consider this pseudo HTML (as it
would look like after the page was rendered)

<html>
<head>
<script src='http://localhost/mywebapp/js/common.js'
language='JavaScript'></script>
</head>
<form id="frmMain" runat="server">
<McAddEditAscx User Control Rendered>
<input type="text" id="searchCompany" size="1"
name="searchCompany" onkeyup="base.findText(this, Company);">
<select name="_McAddEditAscx:Company"
id="_McAddEditAscx_Company">
<option value="something">something</option>
...
</select>
</McAddEditAscx User Control Rendered>
</form>
</html>
Notice that when the UserControl got rendered my dropdownlist with
id="Company" was rendered as _McAddEditAscx:Company

I tried fugding my searchCompany box by doing

<input type="text" id="searchCompany" size="1" name="searchCompany"
onkeyup="base.findText(this, _McAddEditAscx:Company);">

I don't that's a clean solution though.

So how do I access HTML controls that are in a user control using
JavaScript?

THANK YOU!!

Nov 18 '05 #1
1 2600
You can either output the unique id of those controls in your server side
code (which will include the name decoration), or you can iterate through
the controls looking at substrings for the text that you want.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"George Durzi" <gd****@hotmail.com> wrote in message
news:OO**************@TK2MSFTNGP09.phx.gbl...
I have a JavaScript called common.js that is referenced by every ASPX in my web application. In common.js, I have a funtion called findText (which I use to help me navigate through drop down lists by typing the first few letters of an item in the drop down list).

So this is how I would use it:

<input type="text" id="searchCompany" size="1" name="searchCompany"
onkeyup="findText(this, Company);">
<asp:dropdownlist ID="Company" Runat="server"></asp:dropdownlist>

All this is fine on a normal webform. But I run into trouble when my
dropdown list is inside a user control. Consider this pseudo HTML (as it
would look like after the page was rendered)

<html>
<head>
<script src='http://localhost/mywebapp/js/common.js'
language='JavaScript'></script>
</head>
<form id="frmMain" runat="server">
<McAddEditAscx User Control Rendered>
<input type="text" id="searchCompany" size="1"
name="searchCompany" onkeyup="base.findText(this, Company);">
<select name="_McAddEditAscx:Company"
id="_McAddEditAscx_Company">
<option value="something">something</option>
...
</select>
</McAddEditAscx User Control Rendered>
</form>
</html>
Notice that when the UserControl got rendered my dropdownlist with
id="Company" was rendered as _McAddEditAscx:Company

I tried fugding my searchCompany box by doing

<input type="text" id="searchCompany" size="1" name="searchCompany"
onkeyup="base.findText(this, _McAddEditAscx:Company);">

I don't that's a clean solution though.

So how do I access HTML controls that are in a user control using
JavaScript?

THANK YOU!!

Nov 18 '05 #2

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

Similar topics

3
by: Vivek Sharma | last post by:
Hi, I have created a dropdownlist as a web user control. I am using its multiple instances on the webpage. How do I access the selectedValue of each instance? All the instances have different...
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...
1
by: Patrick | last post by:
Problem I have an ASPX file, with a table of 3 columns, 2 rows with a usercontrol in the middle column (in the code snippet stated below, although in reality, the left hand column would also...
5
by: Dan Nash | last post by:
Hi all, I've got a page with a user control on, added via VS. I'm trying to get to a property of the user control (or more precisely, a public var). Here's the code at the top of my aspx...
4
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where...
6
by: evandelagrammaticas | last post by:
Hi all. I have spent the better part of a day scouring the newsgroups and I am sure that I must have come across the solution a number of times - but I am still a real newbie at asp.net so please...
3
by: tshad | last post by:
I am trying to put together a user control (.ascx). Can you access an outside control from it? My control: login2.ascx ****************************************************************...
4
by: tshad | last post by:
Is there a way for a User Control to access an object (such as label or textbox) on the .aspx page that calls it? For example: x.aspx ************************************** .... Sub...
4
by: =?Utf-8?B?R3JlZyBTdGV2ZW5z?= | last post by:
I have an ASP.NET page with a form that contains two user controls: <%@ Register TagPrefix="x" TagName="c1" Src="ctl1.ascx" %> <%@ Register TagPrefix="x" TagName="c2" Src="ctl2.ascx" %> <body>...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.