i have a web-page with two
controls:
Related to Attempt#1 to solve the problem of the page position you can try using this in the aspx page header
<%@ Page MaintainScrollPositionOnPostback="true" %>
and register a javascript in the cbCountry_SelectedIndexChanged
method to set focus at the state combobox.
Go to the setting of the dropdownList
Set AutoPostBack=True ,
Use the AJAX Control Toolkit... it has a CascadingDropDown which would be perfect! :)
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx
I have a trick and it works. It is using a hidden button inside the same update pane the the State dropdown.
<script type="text/javascript">
function ddlCountry_changed() {
document.getElementById('<%= btnLoad.ClientID %>').click();
}
</script>
Country:
<asp:DropDownList ID="ddlCountry" runat="server" onchange="ddlCountry_changed();">
<asp:ListItem Text="Vietnam" Value="1"></asp:ListItem>
<asp:ListItem Text="United State" Value="2"></asp:ListItem>
</asp:DropDownList>
<asp:UpdatePanel ID="updatePanel" runat="server">
<ContentTemplate>
<asp:Button ID="btnLoad" style="display: none" runat="server" OnClick="btnLoad_OnClick" />
State:
<asp:DropDownList ID="ddlState" runat="server">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
Code behind:
protected void btnLoad_OnClick(object sender, EventArgs e)
{
ddlState.Items.Clear();
if (ddlCountry.SelectedValue == "2")
{
ddlState.Items.Add(new ListItem() { Text = "California", Value = "1" });
}
else
{
ddlState.Items.Add(new ListItem() { Text = "Saigon", Value = "2" });
}
}
Updating the DropDownList
controls using javascript won't alter the viewstate, which means that in each post the changes will be overridden.
I have done something similar serializing to JSON the content of the lists in hidden fields and then in server code deserializing it on each post
This is an answer that shows a full working example to show something similar (check the accepted answer).
ASP.NET jQuery double listbox edit and save
BTW In order to get rid of:
Invalid postback or callback argument.
You can disable the viewstate validation, however this is not recommended, you should only do it if you are in an intranet where you can trust most of the time in your users
<%@ Page EnableEventValidation="false"