473,789 Members | 2,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="searchCompa ny" size="1" name="searchCom pany"
onkeyup="findTe xt(this, Company);">
<asp:dropdownli st ID="Company" Runat="server"> </asp:dropdownlis t>

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='JavaS cript'></script>
</head>
<form id="frmMain" runat="server">
<McAddEditAsc x User Control Rendered>
<input type="text" id="searchCompa ny" size="1"
name="searchCom pany" onkeyup="base.f indText(this, Company);">
<select name="_McAddEdi tAscx:Company"
id="_McAddEditA scx_Company">
<option value="somethin g">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="searchCompa ny" size="1" name="searchCom pany"
onkeyup="base.f indText(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 2617
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******** ******@TK2MSFTN GP09.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="searchCompa ny" size="1" name="searchCom pany"
onkeyup="findTe xt(this, Company);">
<asp:dropdownli st ID="Company" Runat="server"> </asp:dropdownlis t>

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='JavaS cript'></script>
</head>
<form id="frmMain" runat="server">
<McAddEditAsc x User Control Rendered>
<input type="text" id="searchCompa ny" size="1"
name="searchCom pany" onkeyup="base.f indText(this, Company);">
<select name="_McAddEdi tAscx:Company"
id="_McAddEditA scx_Company">
<option value="somethin g">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="searchCompa ny" size="1" name="searchCom pany"
onkeyup="base.f indText(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
2796
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 IDs. Thanks Vivek
2
8404
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 submitting the form to update the database. The server doesn't have the client side value any more. It seems to me that as I begin to write the client side javacript code for form validation and client side editing capabilities in order to save...
1
1524
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 have a user control). I have a "footer" on the second/bottom row. However, when the User Control in the middle column, first row is generating a lot of text, the text is "squashing" the text in the second role!
5
1517
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 page... <%@ Register TagPrefix="dI2" TagName="dartsUC_rolodexsearch" Src="dartsUC_rolodexsearch.ascx" %>
4
4222
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 the server generates the HTML based on a passed in parameter. In our case, CustomerID. Every Customer ges a branded website with there logos and webpage etc.. To Avoid having 1 ASP.Net application running for each client I am attempting a more...
6
4076
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 forgive me beforehand if I ask anything really simple or ridiculous. I am going to simplify my query... the structure of my example is ---> page1.aspx ------> page1.aspx.vb --->control1.ascx for the sake of simplicity this is what I am trying...
3
1772
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 **************************************************************** <script runat="server"> Sub Page_Load(sender as Object, e as EventArgs)
4
1685
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 Page_Load(s as Object, e as EventArgs) LoadControl("x.ascx")
4
1466
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> <form runat="Server"> <x:c1 id="con1" runat="Server"> <x:c2 id="con2" runat="Server"> <form> </body>
0
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10195
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.