Asp.net: Restoring Client-side Selecteditem Of Dropdownlist On Server-side
So I have a dropDownList on my page that contains hundreds of items. The user can filter this DDL by typing some text into a textbox. The DDL then gets filtered accordingly (all it
Solution 1:
When user presses a button get current value of dropdown using jQuery and set it in hidden field on page , give hidden field runat="server" so that when it posts back you will get value that was selected. For example
<asp:DropDownList class="myList"></asp:DropDownList>
<asp:Button class="btn"/>
<inputtype="hidden" id="hdnSelectedI" runat="server" class="hiddenControl">
$(document).ready(function(){
$(".btn").click(function(){
var selectedItem = $(".myList").val();
$(".hiddenControl").val(selectedItem);
});
});
I have used clas name selector as ids in aspnet are auto generated. On server side get value of
hdnSelectedItem.Value
, and from that pull from list of items/db maintained on server.
Post a Comment for "Asp.net: Restoring Client-side Selecteditem Of Dropdownlist On Server-side"