If an asp.net DropDownList's is set to EnableViewState=false, DropDownList.SelectedItem returns null.
Then what technique can I use to get the SelectedItem of that DropDownList while keeping that EnableViewState=false?
If an asp.net DropDownList's is set to EnableViewState=false, DropDownList.SelectedItem returns null.
Then what technique can I use to get the SelectedItem of that DropDownList while keeping that EnableViewState=false?
My guess is that the problem is that you're data-binding the drop down list manually in the code behind file. It might help to move your data binding from Page_Load()
to Page_Init()
.
But in my opinion a better solution would be to use an ObjectDataSource to fill in the values of your DropDownList. That way you're sure that you're loading in the values a the correct time in the page life cycle.
Request.Form[yourDropDownList.UniqueID]
UniqueID returns "ctl00$ContentMain$ddlCountry" where as ClientID returns "ctl00_ContentMain_ddlCountry"
The UniqueID is inserted to the name of the HTML form which is used in the postback form name.