如何在刷新页面后保留下拉值 [英] How to dropdown value remain after refresh page
本文介绍了如何在刷新页面后保留下拉值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在刷新后保留dropDown值Page i在下面提到代码
我尝试过:
How to dropDown Value Remain After Refresh Page i mention below Code
What I have tried:
void BindState()
{
DCI_Assign_Inspectors_DetailsClient client = new DCI_Assign_Inspectors_DetailsClient();
DataSet ds = new DataSet();
Prop objprop = new Prop();
client.Open();
objprop.Mode = "1";
objprop.StateCode = "";
try
{
ds = client.BindState(objprop);
if (ds.Tables[0].Rows.Count > 0)
{
DrpState.DataSource = ds;
DrpState.DataTextField = "State_Name";
DrpState.DataValueField = "State_Code";
DrpState.DataBind();
DrpState.Items.Insert(0, new ListItem("--Please Select--", "All"));
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "InvalidArgs", "alert(" + ex.Message + ");", true);
}
finally
{
ds.Dispose();
client.Close();
objprop = null;
}
}
推荐答案
当您单击刷新按钮时,它将重新加载页面,并且IsPostBack
属性变为false
。
因此无法在服务器中处理,
,但使用客户端存储机制 [ ^ ]你将实现这个目标
请参考此在刷新时保留所选值以获取链接下拉列表 [ ^ ]
When you click the refresh button, it will reload the page, and theIsPostBack
property becomesfalse
.
so it cant be handled in Server,
but using Client storage mechanism[^] you shall achieve this
refer this Retain selected value for link dropdown upon refresh [^]
我怀疑,你已经打电话给 Page_Load()事件中的BindState()但未在 IsPostBack 内查看。
如果是,请尝试包装你的 BindState() cal l在IsPostBack内部进行检查,如下所示 -
I suspect, you have called the BindState() in the Page_Load() event but haven't emebeded it inside IsPostBack check.
If so, please try wrapping your BindState() call inside IsPostBack proprty check, somethi ng like following-
if(!Page.IsPostBack)
BindState();
它将绑定第一次加载时的下拉列表和回发时函数调用不会被命中所以问题应该解决。
希望,它有帮助:)
It will bind the dropdown on first load and on postback the function call will not be hit so the issue should be resolved.
Hope, it helps :)
这篇关于如何在刷新页面后保留下拉值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文