J
Jeff Donkersgoed
I have a registration form that updates a province/state droplist when a
country is selected from another droplist. When the user clicks the back
button though, the province list goes back to the prior country, but the
country list remains the same. This would be ok if the country went back to
the prior country as well. Ideally, I would just like the back button to
just go back to the previous page that linked to the registration page
instead.
I tried playing around with EnableViewState a bit without success thinking
that may have something to do with it.
Below are some code snippets:
aspx
<tr>
<td>Country</td>
<td><aspropDownList ID="ddlCountry" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlCountry_SelectedIndexChanged"></aspropDownList></td>
</tr>
<tr>
<td><asp:Label ID="lblProvince" runat="server"></asp:Label></td>
<td><aspropDownList ID="ddlProvince"
runat="server"></aspropDownList></td>
</tr>
aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Look up country info
using (DataSet ds =
NNRDReports.XMLHelper.GetDataSetFromXml(@"Xml\CountryInfo.xml"))
{
DataTable dtCountries = ds.Tables["Country"];
ddlCountry.DataTextField = "Name";
ddlCountry.DataValueField = "Code";
ddlCountry.DataSource = dtCountries;
ddlCountry.DataBind();
ddlCountry.SelectedIndex = 0;
CountryChanged();
}
}
}
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
CountryChanged();
}
private void CountryChanged()
{
ddlProvince.Items.Clear();
// Look up what the country info and populate it into the page
using (DataSet ds =
NNRDReports.XMLHelper.GetDataSetFromXml(@"Xml\CountryInfo.xml"))
{
DataTable dtProvinces = ds.Tables["Province"];
dtProvinces.DefaultView.RowFilter = "CountryCode='" +
ddlCountry.SelectedItem.Value + "'";
lblProvince.Text = (string)dtCountries.DefaultView[0]["RegionType"];
ddlProvince.DataTextField = "Name";
ddlProvince.DataSource = dtProvinces.DefaultView;
ddlProvince.DataBind();
}
}
country is selected from another droplist. When the user clicks the back
button though, the province list goes back to the prior country, but the
country list remains the same. This would be ok if the country went back to
the prior country as well. Ideally, I would just like the back button to
just go back to the previous page that linked to the registration page
instead.
I tried playing around with EnableViewState a bit without success thinking
that may have something to do with it.
Below are some code snippets:
aspx
<tr>
<td>Country</td>
<td><aspropDownList ID="ddlCountry" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlCountry_SelectedIndexChanged"></aspropDownList></td>
</tr>
<tr>
<td><asp:Label ID="lblProvince" runat="server"></asp:Label></td>
<td><aspropDownList ID="ddlProvince"
runat="server"></aspropDownList></td>
</tr>
aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Look up country info
using (DataSet ds =
NNRDReports.XMLHelper.GetDataSetFromXml(@"Xml\CountryInfo.xml"))
{
DataTable dtCountries = ds.Tables["Country"];
ddlCountry.DataTextField = "Name";
ddlCountry.DataValueField = "Code";
ddlCountry.DataSource = dtCountries;
ddlCountry.DataBind();
ddlCountry.SelectedIndex = 0;
CountryChanged();
}
}
}
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
CountryChanged();
}
private void CountryChanged()
{
ddlProvince.Items.Clear();
// Look up what the country info and populate it into the page
using (DataSet ds =
NNRDReports.XMLHelper.GetDataSetFromXml(@"Xml\CountryInfo.xml"))
{
DataTable dtProvinces = ds.Tables["Province"];
dtProvinces.DefaultView.RowFilter = "CountryCode='" +
ddlCountry.SelectedItem.Value + "'";
lblProvince.Text = (string)dtCountries.DefaultView[0]["RegionType"];
ddlProvince.DataTextField = "Name";
ddlProvince.DataSource = dtProvinces.DefaultView;
ddlProvince.DataBind();
}
}