Here is my problem, I have an mvc project with a dropdownlist
control(Server Side) which i populate with data at run time, i have set autopostback
to true,and enabled viewstate
; this dropdown list has a selectedIndexChanged
event handler which was suppose to trigger when a user selects something.
However when the page loads, the Page.IsPostBack
is always false so the datalist is repopulated and hence no change to trigger the event handler. I have read on this post that while asp web forms take care of postback automatically, on MVC I have to manually write the javascript code to trigger the postback.
Do you guys know of any way i can do that so that it goes to the selectedIndexChanged
EventHandler and dont repopulate the dropdown list
again?
EDIT: I have already tried
<script type="text/javascript">
function OnIndexChanged() {
var databaseList = document.getElementById("FeaturedContent_DatabaseList");
__doPostBack(FeaturedContent_DatabaseList, '');
//window.location.href("http://localhost:49729/home/schemas?dbName=SchoolDB");//+ document.getElementById("DatabaseLists").selectedIndex;
//postMessage("h", "http://localhost:49729/home/schemas?dbName=SchoolDB");
//__doPost(
}
</script>