I am relatively new to C#, and I have been researching this across the internet for a few days now. I need the value selected in asp.net DropDownList to be declared as a JavaScript variable. I have looked into <asp:hiddenfield>
's mostly, but I'm not sure if this is the best option to go down. So I have two questions:
- Are
<asp:hiddenfield>
's the best option? How do you declare a C# string into a javascript variable?
<asp:DropDownList runat="server" ID="dropDownID"> <asp:ListItem Text="-- Select Reason --" Value=""></asp:ListItem> <asp:ListItem Text="Booking" Value="1"></asp:ListItem> <asp:ListItem Text="Discussing" Value="2"></asp:ListItem> <asp:ListItem Text="Quotation" Value="3"></asp:ListItem> </asp:DropDownList> <asp:hiddenfield ID="valueInHiddenField" value="" runat="server"/>