I have an ASP.Net dropdown list that is populated using javascript like this:
Dropdown list:
<asp:DropDownList ID="Ddl" runat="server" AutoPostBack="true"
EnableViewState="true"></asp:DropDownList>
The javascript code that populates the dropdown list with "text" is:
var select = document.getElementById('<%= Ddl.ClientID %>');
var option = document.createElement("option");
option.value = '1';
option.innerHTML = "Text";
select.appendChild(option);
It gets filled just fine in client side. I added a button that is supposed to run on server side. On the server side when I try to retrieve the ddl selected value; it gives an exception (Object reference not set to an instance of an object.)
I understand that the ASP.Net ddl control loses the content once form is sent to server?
How would I tackle this issue? I tried putting the value in hidden field and try using Request.Form["HiddenField"].toString();
but it gives the same error. Any help?