0

I am trying to keep the selected value in a drop down box after page reloads by creating session but i am not sure if my logic works because the drop down is not keeping the selected value before the refreshed.: here is what i have:

string txtDDLLocation = ddlLocation.SelectedValue;
Session["MySessionVar"] = txtDDLLocation;
Page.Response.Redirect(Page.Request.Url.ToString(), true);
ddlLocation.SelectedValue = (string)Session["MySessionVar"];
4

2 回答 2

1

你打电话ddlLocation.SelectedValue = (string)Session["MySessionVar"]Response.Redirect

确保在 page_load 事件中加载值

protected void page_load(object sender, EventArgs e)
{
if(Session["MySessionVar"]!=null)
   ddlLocation.SelectedValue = (string)Session["MySessionVar"]
}
于 2013-10-29T17:20:56.870 回答
-2

重定向代码后大声笑设置会话将永远不会到达会话变量

于 2013-10-29T17:12:07.640 回答