简体   繁体   English

运行时生成的控件已为异步回发asp.net禁用

[英]Runtime generated controls disabled for Async Postback asp.net

I want to create at runtime some items that must not hit the "async postback". 我想在运行时创建一些不能击中“异步回发”的项目。

Actually I have a button for each row in my grid view. 实际上,我的网格视图中的每一行都有一个按钮。 This controls must not generate the partial postback but the complete postback ('cause the result must be the download of a report). 该控件不能生成部分回发,而可以生成完整的回发(因为结果必须是报告的下载)。

Actually I tried in 2 ways: 实际上,我尝试了2种方式:

  1. On page load 页面加载

    • recursive search for every controls that is a Button and have the specified class 递归搜索作为Button并具有指定类的每个控件
    • add the item to the ScriptManager via: 通过以下方式将该项目添加到ScriptManager中:

      ScriptManager.GetCurrent(this).RegisterPostBackControl(control); ScriptManager.GetCurrent(本).RegisterPostBackControl(对照);

    • this code is hitted the right number of time, but partial postback is still generated 该代码被打了正确的时间,但是仍然生成了部分回发

  2. On item generation 关于项目生成

    • I add a "OnDataBinding" event to the button generation 我将“ OnDataBinding”事件添加到按钮生成中
    • in this event I do something like: 在这种情况下,我会执行以下操作:

      var button = (Control)sender; var button =(Control)sender;

      ScriptManager.GetCurrent(this).RegisterPostBackControl(button); ScriptManager.GetCurrent(本).RegisterPostBackControl(按钮);

Why isn't this working? 为什么这不起作用?

In both cases I hit the specific case and "register" the controls as "do full postback" so way do I get the partial one? 在这两种情况下,我都碰到了特定情况,并将控件“注册”为“完全回发”,那么我该如何获得部分回发?

Thank you 谢谢

I don't know what you mean by partial postback but I guess you are trying to do something on button click event which you want to occur after page load. 我不知道您所说的部分回发是什么意思,但是我想您正在尝试在按钮单击事件中执行某些操作,该事件要在页面加载后发生。 There is a quick walkaround for this, on pageload event you can check which button was clicked. 有一个快速的解决方法,在pageload事件中,您可以检查单击了哪个按钮。

if(IsPostBack){
    clickedButtonID=Request.Form["__EVENTTARGET"]; 
}

I find out a solution that works and that does not involve any particular code / overriding. 我找到了一个可行的解决方案,并且不涉及任何特定的代码/替代。

I was focussing on the single "automatically-generated" button but when I start thinking about areas and parents everything goes fine. 我当时只专注于“自动生成”按钮,但是当我开始考虑区域和父母时,一切都很好。

As solution I simply register the WHOLE GridView to the Script Manager, by this way, all the controller inside generates a full postback instead of a partial one. 作为解决方案,我只需将WHOLE GridView注册到脚本管理器,通过这种方式,内部的所有控制器都会生成完整的回发而不是部分回发。

In my Page_Load I have now: 在我的Page_Load中,我现在有:

        ScriptManager.GetCurrent().RegisterPostBackControl(grd_Reports);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM