有没有一种方法可以确定<asp:UpdatePanel />是否执行了类似于我们如何使用...
<asp:UpdatePanel />
if(!Page.IsPostBack) { ...snip }
字符串.来确定是否正在发生来自按钮提交的回发。我试图从jQuery检测Ajax请求,但它也会拾取我想排除的UpdatePanel请求。
if (Request.IsAjaxRequest() && !Page.IsUpdatePanelPostback){ // Deal with jQuery Ajax}
if (Request.IsAjaxRequest() && !Page.IsUpdatePanelPostback)
{
// Deal with jQuery Ajax
}
型
px9o7tmv1#
您可以检查回发是否是异步的,以及它是否由查看以下属性的更新面板发出:
ScriptManager.GetCurrent(Page).IsInAsyncPostBackScriptManager.GetCurrent(Page).AsyncPostBackSourceElementID
ScriptManager.GetCurrent(Page).IsInAsyncPostBack
ScriptManager.GetCurrent(Page).AsyncPostBackSourceElementID
字符串
cfh9epnr2#
我不知道这是否会比你的解决方案更好,但你试过吗?
if (ScriptManager.GetCurrent(Page).IsInAsyncPostBack){ Control ctrl = GetControlThatCausedPostBack(Page); if (ctrl is UpdatePanel) { //handle updatepanel postback }}private Control GetControlThatCausedPostBack(Page page){ //initialize a control and set it to null Control ctrl = null; //get the event target name and find the control string ctrlName = Page.Request.Params.Get("__EVENTTARGET"); if (!String.IsNullOrEmpty(ctrlName)) ctrl = page.FindControl(ctrlName); //return the control to the calling method return ctrl;}
if (ScriptManager.GetCurrent(Page).IsInAsyncPostBack)
Control ctrl = GetControlThatCausedPostBack(Page);
if (ctrl is UpdatePanel)
//handle updatepanel postback
private Control GetControlThatCausedPostBack(Page page)
//initialize a control and set it to null
Control ctrl = null;
//get the event target name and find the control
string ctrlName = Page.Request.Params.Get("__EVENTTARGET");
if (!String.IsNullOrEmpty(ctrlName))
ctrl = page.FindControl(ctrlName);
//return the control to the calling method
return ctrl;
qybjjes13#
尝试以下操作:
var controlName = Page.Request.Params.Get("__EVENTTARGET");if (!String.IsNullOrEmpty(controlName)){ // Use FindControl(controlName) to see whether // control is of UpdatePanel type}
var controlName = Page.Request.Params.Get("__EVENTTARGET");
if (!String.IsNullOrEmpty(controlName))
// Use FindControl(controlName) to see whether
// control is of UpdatePanel type
字符串有用链接:
3条答案
按热度按时间px9o7tmv1#
您可以检查回发是否是异步的,以及它是否由查看以下属性的更新面板发出:
字符串
cfh9epnr2#
我不知道这是否会比你的解决方案更好,但你试过吗?
字符串
qybjjes13#
尝试以下操作:
字符串
有用链接: