要确定回发是否是部分更新,您可以使用ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack
. 这是一个例子:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
// get a reference to ScriptManager and check if we have a partial postback
if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
{
// partial (asynchronous) postback occured
// insert Ajax custom logic here
}
else
{
// regular full page postback occured
// custom logic accordingly
}
}
}
要获取导致 PostBack 的更新面板,您可以查看ScriptManager.GetCurrent(Page).UniqueID
并分析它。这是一个这样做的例子:
public string GetAsyncPostBackControlID()
{
string smUniqueId = ScriptManager.GetCurrent(Page).UniqueID;
string smFieldValue = Request.Form[smUniqueId];
if (!String.IsNullOrEmpty(smFieldValue) && smFieldValue.Contains("|"))
{
return smFieldValue.Split('|')[0];
}
return String.Empty;
}
参考: