|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
issue: accessing value of dropdownlist in a user controlI am having trouble getting the value of a dropdownlist from javascript. I have a form that contains a user control that has a drop downlist. the usercontrol is declared as follows: protected frm3H_1 Frm3H_11; in the user control I declare the dropdownlist protected System.Web.UI.WebControls.DropDownList lstdirectorindirectownership; there is some javascript included in the form that is trying to access the value of the dropdownlist. I placed this in my usercontrol ascs file. <tr> <td><span class="bodytext"> <asp:dropdownlist id="lstdirectorindirectownership" runat="server" Width="92px"> <asp:ListItem Value="1">D</asp:ListItem> <asp:ListItem Value="0">I</asp:ListItem> </asp:dropdownlist></span></td> </tr> In the javascript I am trying to get it by the following. var selectedIndex = document.table1.Frm3H_11_lstdirectorindirectownership.selectedIndex alert("Selected Index is " + selectedIndex); var selectedValue = document.table1.Frm3H_11_lstdirectorindirectownership[selectedIndex].value; alert("Selected Value is \'" + selectedValue + "\'"); It does not seem to work. Can anyone provide some insight to what I should be doing? -- E of the City ASP.NET renders its server controls using a unique naming strategy:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconwebformscontrolidentification.asp
To be able to find a control using client-side scripting you need to locate the element by its ClinetID. Therefore you have to use the RegisterStartupScript to send to the browser variables containing the ClientIDs of the objects you intend to manipulate. To see an example of such client-side scripting of server side object, you might review the source code of this demo from my website (which uses a TreeView but the concept is the same when you attempt to get the clientID for the dropdonwlists) Show quoteHide quote "E" wrote: > hi, > > I am having trouble getting the value of a dropdownlist from javascript. > > I have a form that contains a user control that has a drop downlist. > > the usercontrol is declared as follows: > protected frm3H_1 Frm3H_11; > > in the user control I declare the dropdownlist > protected System.Web.UI.WebControls.DropDownList lstdirectorindirectownership; > > > there is some javascript included in the form that is trying to access the > value of the dropdownlist. > > I placed this in my usercontrol ascs file. > <tr> > <td><span class="bodytext"> > <asp:dropdownlist id="lstdirectorindirectownership" runat="server" > Width="92px"> > <asp:ListItem Value="1">D</asp:ListItem> > <asp:ListItem Value="0">I</asp:ListItem> > </asp:dropdownlist></span></td> > </tr> > > > In the javascript I am trying to get it by the following. > > var selectedIndex = > document.table1.Frm3H_11_lstdirectorindirectownership.selectedIndex > alert("Selected Index is " + selectedIndex); > var selectedValue = > document.table1.Frm3H_11_lstdirectorindirectownership[selectedIndex].value; > alert("Selected Value is \'" + selectedValue + "\'"); > > It does not seem to work. Can anyone provide some insight to what I should > be doing? > > > -- > E of the City I figured it out. took me a while but here is the solution.
var Index = document.table1.Frm3H_11_lstdirectorindirectownership.options.selectedIndex; var Value = document.table1.Frm3H_11_lstdirectorindirectownership.options[Index].value; The rest is ok. -- Show quoteHide quoteE of the City "E" wrote: > hi, > > I am having trouble getting the value of a dropdownlist from javascript. > > I have a form that contains a user control that has a drop downlist. > > the usercontrol is declared as follows: > protected frm3H_1 Frm3H_11; > > in the user control I declare the dropdownlist > protected System.Web.UI.WebControls.DropDownList lstdirectorindirectownership; > > > there is some javascript included in the form that is trying to access the > value of the dropdownlist. > > I placed this in my usercontrol ascs file. > <tr> > <td><span class="bodytext"> > <asp:dropdownlist id="lstdirectorindirectownership" runat="server" > Width="92px"> > <asp:ListItem Value="1">D</asp:ListItem> > <asp:ListItem Value="0">I</asp:ListItem> > </asp:dropdownlist></span></td> > </tr> > > > In the javascript I am trying to get it by the following. > > var selectedIndex = > document.table1.Frm3H_11_lstdirectorindirectownership.selectedIndex > alert("Selected Index is " + selectedIndex); > var selectedValue = > document.table1.Frm3H_11_lstdirectorindirectownership[selectedIndex].value; > alert("Selected Value is \'" + selectedValue + "\'"); > > It does not seem to work. Can anyone provide some insight to what I should > be doing? > > > -- > E of the City
GridViewRow.DataItem is null
Server Control to manipulate GridView Checkbox items under a RadioButton Access data in ObjectDataSource no FormView for create/insert page Datagrid custom paging always loads page 1 Datagrid cancel command does not work when adding new record custom button/link in detailsview commandfield section Video capture control in asp.net 2.0 How well is a performance of a Menu Control |
|||||||||||||||||||||||