Java script cannot differentiate client side controls in user control used multiple on same webform

I have a textbox with a automcomplete extender and a client side link that, when clicked, changes style.display from "none" to "" to display a div that contains a listview with all possible choices for the text box.  I am using javascript to change the div style.display when the link is clicked.  When I have two instances of the usercontrol on the same webform, both links display the div on the first control.  How can the client side javascript tell the difference between the two divs?

11/8/2008 5:08:25 AM 24353 articles. 2 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 0

Try putting the javascript of the user control in a seperate file like javascriotuesrcontrol.js,add refer the javascript in the usercontrol,i think this will solve your problem.


Rajesh Kamalakshan

11/8/2008 5:25:16 AM

I moved javascript to an external file and now I am getting error '' is null or not an object.  I have included the control below which is intended to be a usercontrol.  Original problem was that if I have more than one of these on a single webform, the javascript for each instance of the control always acts on the first divUserSearch on the page.

function OnUserSearchClick() {

var myDiv = document.getElementById("divUserSearch")

if ( == "none") = "";

else = "none";

script type="text/javascript" src="../UserTextBoxScript.js">


<div style="font-size: 0.8em; float:left;">

<asp:TextBox ID="txtUserName" runat="server" Width="250px"></asp:TextBox>

<ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"

TargetControlID="txtUserName" EnableCaching="true" ServiceMethod="GetUserNames"

MinimumPrefixLength="2" ServicePath="/WetSuiteWFM/UserAutoComplete.asmx">


<a onclick="OnUserSearchClick()" href="#">

<img alt="(search)" src="../images/find.gif" style="border-bottom-style: groove; vertical-align:text-bottom;

border-color: #F0F4F9; border-right-style:groove;

background-color: #F0F4F9;" />


<div id="divUserSearch" style="display: none; width: 300px; padding-left: 25px; position: absolute"



<span class="SectionHeader">User Account Search</span></p>

<asp:ListBox ID="lstUserName" runat="server" Width="255px" Height="25px" AutoPostBack="true"></asp:ListBox>

<asp:Label ID="lblModalStatus" runat="server" EnableViewState="false" ForeColor="red"

Text="" />

<asp:Label ID="lblUserNameSearchField" runat="server" Text="" ForeColor="Red" />



11/8/2008 2:07:52 PM

I figured this out.  By adding the following attribute to my list box and sending the textbox clientID from server side code-behind in the Page_Load event... 

If Not IsPostBack Then

Dim myAttribute As String = "setUserNameTextBox(this.options[this.selectedIndex].value, " & txtUserName.ClientID & ")"


End If

-------------- I get the fully qualified ClientID including the usercontrol segment for my javascript below. 

function setUserNameTextBox(lstValue, tbClientID) {

tbClientID.value = lstValue;


11/11/2008 5:23:47 PM

need this line in the Page_load event too.  Sorry, forgot I broke it into two separate lines when I was experimenting.

Dim myAttribute As String = "setUserNameTextBox(this.options[this.selectedIndex].value, " & txtUserName.ClientID & ")"

lstUserName.Attributes.Add("onclick", myAttribute)

11/11/2008 5:26:34 PM

Similar Artilces:

How to access dynamically Html controls (client side controls) using C# server side scripts
Folks,I have problem try to to access dynamically Html controls (client side controls) using C# server side scripts. Please give me helps.     The error is as follows Exception Details: System.InvalidCastException: Specified cast is not valid.Source Error: Line 79: { Line 80: Control c = Page.FindControl("ddlTC" + i); Line 81: ((DropDownList)c).DataSource = mdt; Line 82: ((DropDownList)c).DataTextField = "ClassID"; Line 83: ((DropDownList)c).DataValueField = "Course"; My aspx page source codes: ...<...

Can we access controls within user controls on the client side without using ctl0_ControlsName
When we create controls within our user controls, the way we can access those controls in client side is i guess:getElementByID('the client id')but the server chnages the names of those controls to:  clt0_Controlsname, so i always have to use add ctl0 when I want to access to my controls of the user control on the client there a solution to this or that s just the way it isthank you Thanks a lot, I appreciate your taking the time to help me. Hello tutus,this is maybe the most frequent question in this forum, did you notice?This problems is related to all server co...

Combining a server-side control with a client-side control!
Hi all, I am trying to combine a server-side control with a client-side control. I have created a listbox in both sides, the client-side control's code is: <select size="4" name="lstFruit" id="Select1" ondblclick="lst_dblClick" visible="false"> <option value="Banana">Banana</option> <option value="Apple">Apple</option> <option value="Mango">Mango</option> <option value="Orange">Orange</option> </select> The other one is the server-side control which has this code:   I wanted to add the ondblClick attribute to the se...

What are diff Server-side control and Client-side control ?
What are diff Server-side control and Client-side control ? and diff server -side coding and client -side coding ? please help I have answered the first part of your question in your previous posting. Server-side coding languages are ASP, ASP.NET, PHP, CGI (Perl) and many, many more. They are used to create dynamic web content (based on additional information that is attached to the request) and are often used to extract information from databases. Client-side coding languages are JavaScript, VBScript, EMACScript and are used to create dynamic content that responds to the u...

Loaing Image to an Image COntrol using client side java script
SIr How can I Load an Image to an Image Control using JavaScript Expecting reply C T Ranjith Hi ctranjith, Try the following snipplet and then call it wherever you need it: function LoagImage() { document.getElementById('imgControl1').src = document.getElementById('btnExplore').value; } Hope it helps.MIGUELÓN.-----------------------------------------Rezad a vuestros dioses, amad a vuestras mujeres y luchad por vuestra patria! ----------------------------------------...

Web User Control +Client Side Control
Two Questions if Possible:  1: Some controls have methods/properties that can be gotten/set client-side (IE ASP:Timer).  Can usally access them by "$find('<%=Control.ClientID%>').get_(set_)name()".  I made a User Control that has a "Enabled" Propertiy (basically sets a bunch of its components to "visible = false" and then a Timer.Enabled=false).  I can't access my user controls "enabled" via client side script (IE $find(UserControl.ClientID).set_enabled(false)).  How do I bundle this type of fu...

List of client side function of extenders and controls for client side
Hello All,I am using AJAX control toolkit for my current project. Now I need to find out what client side functions I can call on an extender. Lets say I am using a PopControlExtender. Now I want to show the popup from a JS funtions.If I can do a guess then it would be something like this$find('ppce').show();From where I can find what client side functions I can call on those extensders. This is really a frusterating thing. I learn about extenders only from Learn tutorials, no help here and there. Can anybody please tell me where are documentations about all the extenders in the tool...

Client Side Scripts and User Controls
I am trying to implement a simple site which contains a SINGLE aspx page (default.aspx) and a few user controls.  All the user controls are available on the default.aspx page; hence we are not dynamically creating them.  Based on the end user selection, the proper user control is set to visible = true.  (Yes, I know this design is not the best - all i have to work with)Scenario:Default page displays UC1 at startup.  The end user selects a link on the default page.  A partial postback hides all the UCs and set the desired UC's visibility=true (UC2).All works ...

User Controls and Client Side Script
I have been using the sedraftx object as defined below with GridViews.  Now I want to make a UserControl that uses it so I don't have to build it on every page I want to use it.  When I attempt this I get an error saying the sedraftx object is not defined.  ?? An ImageButton in the GridView has this value set on RowDataBind .OnClientClick = "sedraftx.DraftFile = '" + linkToFile + "'; return false" The sedraftx object exists on the page as     <asp:Panel ID="seDraftXPanel" runat="server" Visible="False">    &nbs...

Passing Server Side Control to Client Side Script
Hi All, I have an asp:DropDownList and an asp:TextBox on my form. I want to disable or enable the textbox depending on the selection in the dropdown. I am using master pages and the problem is that when I use the onChange event for the dropdown on the client side, I don't know the ID of the the textbox on the client side to disable or enable it.  How can something like this be done? Thanks,AKA You can use the ClientID property of a control to determine the ID, something like:  <script type="text/javascript"> function ShowMeTheID(){ alert('...

Client side clock using server side controls
Is it possible to create a client side clock using a server side control (label or textbox) in C# without accessing JavaScript?  If so, how? In principal it is possible, it depends how often you need to reload this clock ... if every second than: 1. It is no sens to do I mean 2. You need than to make setTimeout client script, to refresh page every second With FastPage it seems more real task ...

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in ( required field, range validator and others) question is the required field validator is a server side control. So does that mean that it does a post back? it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

Is there a correspondance for each server side control to be equivalent to a client side html control
Where can find the list and can use that equivalence and what is its usage plsThanksThanks a lot, I appreciate your taking the time to help me. What exactly do you mean? A correspondence of what?All controls have a ClientID property, which for most controls tells the DOM element ID that will be used in the HTML rendering. Aside from that certain controls might offer additional client-side functionality, but there's no one standard.Thanks,EilonBlog: I mean. When I am using html control in my aspx page like:  <input type=text ..>  and...

communication between client side(java script) and server side in .net project
I have a question which is, when building a .net project, we are able to use server side code and client side code(java script). How do they communicate? Thanks Client Side coding works with the WebBrowser. So when ever you write client side code you have to keep browser compatability in your mind and you have to code. Server Side code works with Web Server (IIS) and it's ASPNET ISAPI's. The won't directly communicate with each other. But using AJAX you can all server side code from Client Side! Example article on Ajax@

Web resources about - Java script cannot differentiate client side controls in user control used multiple on same webform -

MyPad Launches Twitter Integration to Differentiate From Facebook’s Forthcoming iPad App
MyPad, arguably the most popular unofficial Facebook iPad app, will push the first phase of a Twitter integration this week. MyPad developer ...

Feed reader developers here's an easy way to differentiate your service and have your users love you ...
You all read and write OPML subscription lists , right? Let's go one step further, and let users subscribe to OPML subscription lists. How ...

Microsoft Dynamics CRM differentiates YapiKredi's pension services - YouTube
YapiKredi Emeklilik, is a subsidiary of YapiKredi Bank - one of the largest banks in Turkey and has been offering life insurance and pension ...

Storage Infrastructure Helps Differentiate and Adds Value to Cloud Storage Services - ARN
The source for IT industry news, views and analysis across the channel, business and technology

'Deregulation will allow universities to differentiate' (02:31)
Vice-Chancellor of ANU Professor Ian Young outlines why he is in favor of the governments plan to deregulate universities.

'Deregulation will allow universities to differentiate' (02:31)
Vice-Chancellor of ANU Professor Ian Young outlines why he is in favor of the governments plan to deregulate universities.

Fugoo Bluetooth speaker differentiates with 40hr battery, incredible waterproofing and robust ecosystem ...
... Visit 9to5Mac to find more special coverage of iPhone , Reviews , and Bluetooth . What do you think? Discuss "Fugoo Bluetooth speaker differentiates ...

NetApp Strives to Differentiate in Commoditized Business
... storage is fast becoming a commoditized service. And with NetApp's core customer base spending over $1 million per year, it's hard to differentiate ...

James Murdoch: Debate Gives Fox Business Chance ‘To Differentiate Itself’
... , the company’s chief executive, said next week’s Republican presidential debate offers one of their newest brands, Fox Business, to “differentiate ...

Nokia Shows Off Windows Tablet, Looks to Differentiate Lumia 2520 With Connectivity, Design
... Ifi Majid, Nokia’s head of product marketing for North America, in an interview with AllThingsD . “We thought there was an opportunity to differentiate ...

Resources last updated: 11/25/2015 5:03:01 PM