asp.net 如何检查UpdatePanel是否回发?

vbkedwbf  于 2023-11-20  发布在  .NET
关注(0)|答案(3)|浏览(124)

有没有一种方法可以确定<asp:UpdatePanel />是否执行了类似于我们如何使用...

  1. if(!Page.IsPostBack) { ...snip }

字符串
.来确定是否正在发生来自按钮提交的回发。
我试图从jQuery检测Ajax请求,但它也会拾取我想排除的UpdatePanel请求。

  1. if (Request.IsAjaxRequest() && !Page.IsUpdatePanelPostback)
  2. {
  3. // Deal with jQuery Ajax
  4. }

px9o7tmv

px9o7tmv1#

您可以检查回发是否是异步的,以及它是否由查看以下属性的更新面板发出:

  1. ScriptManager.GetCurrent(Page).IsInAsyncPostBack
  2. ScriptManager.GetCurrent(Page).AsyncPostBackSourceElementID

字符串

cfh9epnr

cfh9epnr2#

我不知道这是否会比你的解决方案更好,但你试过吗?

  1. if (ScriptManager.GetCurrent(Page).IsInAsyncPostBack)
  2. {
  3. Control ctrl = GetControlThatCausedPostBack(Page);
  4. if (ctrl is UpdatePanel)
  5. {
  6. //handle updatepanel postback
  7. }
  8. }
  9. private Control GetControlThatCausedPostBack(Page page)
  10. {
  11. //initialize a control and set it to null
  12. Control ctrl = null;
  13. //get the event target name and find the control
  14. string ctrlName = Page.Request.Params.Get("__EVENTTARGET");
  15. if (!String.IsNullOrEmpty(ctrlName))
  16. ctrl = page.FindControl(ctrlName);
  17. //return the control to the calling method
  18. return ctrl;
  19. }

字符串

展开查看全部
qybjjes1

qybjjes13#

尝试以下操作:

  1. var controlName = Page.Request.Params.Get("__EVENTTARGET");
  2. if (!String.IsNullOrEmpty(controlName))
  3. {
  4. // Use FindControl(controlName) to see whether
  5. // control is of UpdatePanel type
  6. }

字符串
有用链接:

相关问题