我在包含篩選字段並返回WhereClause的aspx頁面上有一個用戶控件。用戶控制將在單擊搜索時引發名爲FilterApplied的事件。正在運行頁面加載多次
在我的主要形式,我添加控件:
<uc1:Filter runat="server" ID="Filter" /> <br />
在我後面的代碼我有:
protected void Page_Load(object sender, EventArgs e)
{
//Register event when filter is changed.
this.Filter.FilterApplied += new EventHandler(this.FilterApplied);
if (Page.IsPostBack)
{ //Do some things that take long
}
}
protected void FilterApplied(object sender, EventArgs e)
{
//Reload the page to refresh the graphs.
Page_Load(sender, e);
}
問題是: 當我點擊搜索我的用戶控件,Form_Load運行兩次。一次,因爲它被重新加載,然後又一次,因爲我從FilterApplied調用它。如果我沒有從FilterApplied中調用它,則where條款仍然是空的。
如何確保Page_Load只在點擊搜索時運行一次?
請不要從你的'FilterApplied'方法調用'Page_Load'。 –
不工作。 「如果我沒有從FilterApplied中調用它,那麼where條款仍然是空的。」 –
爲什麼這個問題不清楚或沒有用(或者顯示缺乏研究工作?如果還不清楚,我可以嘗試糾正它。) –