How to find control in Javascript
-
Hi All, I have to find a control through Javascript which I have generate dynamically through codebehind. For ex: DropDownList ddlCombo = new DropDownList(); ddlCombo.ID = "Combo1"; ddlCombo.CssClass = "text"; ddlCombo.Width = 250; I need to find the ddlCombo Control in Javascript with it selected index. How do I do this?? Thanks in advance...
-
Hi All, I have to find a control through Javascript which I have generate dynamically through codebehind. For ex: DropDownList ddlCombo = new DropDownList(); ddlCombo.ID = "Combo1"; ddlCombo.CssClass = "text"; ddlCombo.Width = 250; I need to find the ddlCombo Control in Javascript with it selected index. How do I do this?? Thanks in advance...
In which container you added ddlCombo control ?
Parwej Ahamad g.parwez@gmail.com
-
In which container you added ddlCombo control ?
Parwej Ahamad g.parwez@gmail.com
Thanks for the reply. I am adding the control in tab container again tab is generated dynamically. It works fine with I run on my machine but it doesnt work on other machine since the ID is different. Please tell me how do I do this... Thanks again...
-
Hi All, I have to find a control through Javascript which I have generate dynamically through codebehind. For ex: DropDownList ddlCombo = new DropDownList(); ddlCombo.ID = "Combo1"; ddlCombo.CssClass = "text"; ddlCombo.Width = 250; I need to find the ddlCombo Control in Javascript with it selected index. How do I do this?? Thanks in advance...
Hi, you need to find that control on any event or what ? you can use 2 ways : 1. In code behind itself u can add attribute to control e.g you can use button click event btnAdd.Attributes["onclick"] = "javascript:DisableControl('"+ddlCombo.ClientID+"');"; and in javascript if(document.getElementById(ddvalue).getAttribute("selectedIndex") or u can directly pass selected index ito javascript 2. in your javascript document.getElementById('Combo1').getAttribute ("selectedIndex") will give u control's index but i m not sure.
pallavi
-
Hi, you need to find that control on any event or what ? you can use 2 ways : 1. In code behind itself u can add attribute to control e.g you can use button click event btnAdd.Attributes["onclick"] = "javascript:DisableControl('"+ddlCombo.ClientID+"');"; and in javascript if(document.getElementById(ddvalue).getAttribute("selectedIndex") or u can directly pass selected index ito javascript 2. in your javascript document.getElementById('Combo1').getAttribute ("selectedIndex") will give u control's index but i m not sure.
pallavi
Hi Pallavi, Thanks for the reply but I have done this and it wroks fine. But when I upload my project on server the ID is different and therefore my javascript function doesnt work. Thats is why I need to use .ClientID. All the controls on my form are generate dynamically. Please help me... Thanks again...
-
Hi All, I have to find a control through Javascript which I have generate dynamically through codebehind. For ex: DropDownList ddlCombo = new DropDownList(); ddlCombo.ID = "Combo1"; ddlCombo.CssClass = "text"; ddlCombo.Width = 250; I need to find the ddlCombo Control in Javascript with it selected index. How do I do this?? Thanks in advance...
After adding this DropDownlist to the content i think you can get its client id Check it
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
After adding this DropDownlist to the content i think you can get its client id Check it
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
Hey Sandeep, thanks the reply. I am doing something like this : var Country = $find('<%=ddlCountry.ClientID%>'); but it says The name 'ddlCountry' does not exist in the current context Since the control in not available in .acsx as I have created it in code behind. I hope I am doing right???
-
Hey Sandeep, thanks the reply. I am doing something like this : var Country = $find('<%=ddlCountry.ClientID%>'); but it says The name 'ddlCountry' does not exist in the current context Since the control in not available in .acsx as I have created it in code behind. I hope I am doing right???
Might be ddlCounty is not accessible there as it must be local variable in any method can you post the code related to drop down list ?
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Might be ddlCounty is not accessible there as it must be local variable in any method can you post the code related to drop down list ?
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
Thanks again. Here is the code: I am adding this DropDownList to tab Container: DropDownList ddlCountry = new DropDownList(); ddlCountry.ID = "ddlCountry"; ddlCountry.CssClass = "text"; ddlCountry.Width = 250; tab1.Controls.Add(ddlCountry); how do I get this ID in Javascript??
-
Thanks again. Here is the code: I am adding this DropDownList to tab Container: DropDownList ddlCountry = new DropDownList(); ddlCountry.ID = "ddlCountry"; ddlCountry.CssClass = "text"; ddlCountry.Width = 250; tab1.Controls.Add(ddlCountry); how do I get this ID in Javascript??
Check the id of DDL after adding to tab like tab1.Controls.Add(ddlCountry); ddlCounty.Clientid; that will give you client id Now it depends on your code how are you adding this tab to the main content page
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Thanks again. Here is the code: I am adding this DropDownList to tab Container: DropDownList ddlCountry = new DropDownList(); ddlCountry.ID = "ddlCountry"; ddlCountry.CssClass = "text"; ddlCountry.Width = 250; tab1.Controls.Add(ddlCountry); how do I get this ID in Javascript??
Another way instead of using ASP dropdown list you can use HtmlSelect Its id will changed runtime you can give data source and datamember to it HtmlSelect ddl = new HtmlSelect(); ddl.Items.Add(new ListItem("Sandeep","Sandeep")); ddl.ID="Sandeep"; PlaceHolder1.Controls.Add(this.Button1); PlaceHolder1.Controls.Add(ddl);
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "