I have dynamic dropdownlists.Some dropdownlists is disabled in javascript.I know the data in disabled controls will not be posted back to server from client.But I still want to detect the dropdownlists and get selected value on server side.
You can use some alternate way to get the selected values of the disabled drop down lists. Use a hidden field to store information in a format like <ddlId>:<selectedvalue>~<ddlId>:<selectedvalue>. You can parse this information at server side that will give
you a drop down list id and its selected value. Look at a code sample.
Nghianx1987
Member
17 Points
26 Posts
How to detect server controls which has attribute has been changed in javascript
Apr 18, 2012 02:48 AM|LINK
Hello all,
I have dynamic dropdownlists.Some dropdownlists is disabled in javascript.I know the data in disabled controls will not be posted back to server from client.But I still want to detect the dropdownlists and get selected value on server side.
Can you help me a solution for my issue?
thank all
Pankaj.Sharm...
Contributor
2350 Points
387 Posts
Re: How to detect server controls which has attribute has been changed in javascript
Apr 18, 2012 07:06 AM|LINK
You can use some alternate way to get the selected values of the disabled drop down lists. Use a hidden field to store information in a format like <ddlId>:<selectedvalue>~<ddlId>:<selectedvalue>. You can parse this information at server side that will give you a drop down list id and its selected value. Look at a code sample.
MyPage1.aspx <script type="text/javascript"> function onDisableClick() { document.getElementById('ddlMonth').disabled = true; document.getElementById('hdnState').value = 'ddlMonth' + ":" + document.getElementById('ddlMonth').value; return false; } </script> <body> <form id="form1" runat="server"> <div> <select id="ddlMonth" name="ddlMonth" runat="server"> <option label="One" value="1"></option> <option label="Two" value="2"></option> <option label="Three" value="3"></option> </select> </div> <br /> <asp:Button ID="btnOkay" runat="server" onclick="btnOkay_Click" meta:resourcekey="Okay"/> <br /> <br /> <button id="btnDisable" value="Disable DDL" onclick="return onDisableClick();">Disable</button> <input id="hdnState" type="hidden" runat="server" /> </form> </body> MyPage1.aspx.cs protected void btnOkay_Click(object sender, EventArgs e) { string[] ddlValueList = hdnState.Value.Split('~'); foreach (string ddlValue in ddlValueList) { string[] ddlInfo = ddlValue.Split(':'); string ddlId = ddlInfo[0]; string selectedValue = ddlInfo[1]; } }Hope this helps.
Nghianx1987
Member
17 Points
26 Posts
Re: How to detect server controls which has attribute has been changed in javascript
Apr 18, 2012 08:52 AM|LINK
Thank you for your help.
I think your solution can help me fix my problem.
Thank you very much