asppostbacktrigger_如何以编程方式注册AsyncPostBackTrigger时将UpdatePanel设置为自动更新?...

I have a Button which will trigger an UpdatePanel, but it is in a different container so if I put my code like below :

There will be a runtime server error : "A control with ID 'btnSearchFilter' could not be found for the trigger in UpdatePanel 'uptxtQuickSearch'."

So I've to register it on the Page_load event with ScriptManager :

ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);

scriptManager.RegisterAsyncPostBackControl(btnSearchFilter);

but in this case, I still have to update the UpdatePanel manually by using Update() method on the end of btnSearchFilter_click event.

Is there any way to update the panel automatically while registering the trigger on the code-behind?

Talk1:

If possible, I would encourage you to move away from updatepanels and the old way of doing ajax in asp.net. I find that it's much more manageable to do your ajax in javascript.

Talk2:

thanks for the feedback, did you mean like using jQuery.ajax method? I know it's resources-wise but I can't see the "much more manageable" part of it, can you help me find a site that explain it in details?

Talk3:

There are several tutorials online. Here is one example: code.tutsplus.com/tutorials/…

Talk4:

The downside to updatepanels/asp.net ajax toolkit is that it abstracts ajax to the point where many developers don't fully grasp the concept of it. I also find it to be inflexible.

Solutions1

I've found a solution for this issue. It turns out that you don't really need to register the control using RegisterAsyncPostBackControl method.

you just need to add the trigger on Page_Init event and use the control.UniqueID if the control cannot be found on the runtime.

So the aspx will be like this :

and in code-behind :

protected void Page_Init(object sender, EventArgs e)

{

uptxtQuickSearch.Triggers.Add(new AsyncPostBackTrigger() { ControlID = btnSearchFilter.UniqueID });

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值