如何检查的UpdatePanel是否回发? [英] How to check whether UpdatePanel is posting back?
本文介绍了如何检查的UpdatePanel是否回发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法,以确定是否< ASP:UpdatePanel中/>
执行了阿贾克斯回发类似我们如何使用...
如果(!Page.IsPostBack){...}剪断
...,以确定是否从一个按钮回发提交正在发生。
我想检测从jQuery的Ajax请求,但它拿起UpdatePanel的要求,以及我要排除如...
如果(Request.IsAjaxRequest()及和放大器;!Page.IsUpdatePanelPostback)
{
//处理jQuery的阿贾克斯
}
解决方案
我不知道这是否会工作,任何比你更好的解决方案,但你尝试过:
如果(ScriptManager.GetCurrent(页).IsInAsyncPostBack)
{
控制CTRL = GetControlThatCausedPostBack(页);
如果(CTRL为的UpdatePanel)
{
//处理的UpdatePanel回发
}
}
私人控制GetControlThatCausedPostBack(页)
{
//初始化控制,并将其设置为null
控制CTRL = NULL;
//获取事件目标名称,并找到控制
字符串ctrlName = Page.Request.Params.Get(__ EVENTTARGET);
如果(!String.IsNullOrEmpty(ctrlName))
CTRL = page.FindControl(ctrlName);
//控制返回给调用方法
返回CTRL;
}
Is there a way to determine if an <asp:UpdatePanel />
has performed an Ajax postback similar to how we can use...
if(!Page.IsPostBack) { ...snip }
... to determine if a postback from a button submit is taking place.
I'm trying to detect Ajax requests from jQuery, but it's picking up UpdatePanel requests as well which I want to exclude eg...
if (Request.IsAjaxRequest() && !Page.IsUpdatePanelPostback)
{
// Deal with jQuery Ajax
}
解决方案
I don't know if this will work any better than your solution, but have you tried?:
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;
}
这篇关于如何检查的UpdatePanel是否回发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文