【问题标题】:Full postback triggered by CheckBox inside GridView inside UpdatePanel由 UpdatePanel 内 GridView 内的 CheckBox 触发的完整回发
【发布时间】:2017-05-13 11:14:07
【问题描述】:

我在 UpdatePanel 中有一个 GridView。在模板字段中是一个复选框,我用于标记项目。从功能上讲,这可以正常工作,但 CheckBox 始终会触发整页回发,而不是部分回发。如何让 CheckBox 触发部分回发?

<asp:GridView ID="gv_test" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:CheckBox ID="cb_View_CheckAll" runat="server" AutoPostBack="true" OnCheckedChanged="cb_View_CheckAll_CheckedChanged"/>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

【问题讨论】:

    标签: asp.net gridview updatepanel


    【解决方案1】:

    使用triggerscriptmanager

    <asp:ScriptManager ID="script" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel" runat="server">
        <ContentTemplate>
    
        </ContentTemplate>
        <Triggers>
            <asp:PostBackTrigger ControlID="cb_View_CheckAll" />
        </Triggers>
    </asp:UpdatePanel>
    

    【讨论】:

    • 因为 CheckBox 放置在网格视图中,因此编译器无法直接找到此子控件并触发编译器错误 'A control with ID 'cb_View_CheckAll' could not be found for the trigger in UpdatePanel 'UpdatePanel1 '.'
    【解决方案2】:

    在您的 ScriptManager 中添加 EnablePartialRendering="true"

    <asp:ScriptManager ID="ScriptManager1" runat="server" EnableViewState="False" EnablePartialRendering="true" EnableScriptGlobalization="true" > </asp:ScriptManager>
    

    或者在代码后面尝试添加 AsyncPostbackTrigger

    ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(gv_test); 
    

    【讨论】:

    • 我应该在哪里添加 AsyncPostbackTrigger,我的意思是在哪个事件中?
    • @UsfNoor 在您的 Pageload 中,但不在 !Ispostback
    猜你喜欢
    • 2011-06-19
    • 2013-07-02
    • 2014-07-30
    • 1970-01-01
    • 2014-08-21
    • 2018-03-19
    • 2010-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多