Javascript 导致完全回发的子控件UpdatePanel

Javascript 导致完全回发的子控件UpdatePanel,javascript,asp.net,Javascript,Asp.net,我试图将UpdatePanel提取到一个子用户控件,以便在同一页面中多次使用它。但是,当我从主页上调用子控件上的_doPostback时(在页面加载结束时,在加载数据之前需要获得一些其他信息),它会刷新整个页面,导致无限循环 然而,真正让我恼火的是,当完全相同的UpdatePanel被嵌入到主页中而不是子控件中时,部分回发就起作用了!我希望有人知道为什么 MainPage.ascx: <%@ Register TagPrefix="test" TagName="GridControl" S

我试图将UpdatePanel提取到一个子用户控件,以便在同一页面中多次使用它。但是,当我从主页上调用子控件上的_doPostback时(在页面加载结束时,在加载数据之前需要获得一些其他信息),它会刷新整个页面,导致无限循环

然而,真正让我恼火的是,当完全相同的UpdatePanel被嵌入到主页中而不是子控件中时,部分回发就起作用了!我希望有人知道为什么

MainPage.ascx:

<%@ Register TagPrefix="test" TagName="GridControl" Src="~/Controls/GridControl.ascx" %>

<asp:ScriptManager ID="SM" runat="server" EnablePageMethods="true">

<test:GridViewControl ID="child" runat="server" />

<asp:UpdatePanel ID="embedded" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:GridView runat="server" AllowPaging="true" OnPageIndexChanging="gridView_PageIndexChanging">
            <Columns>
                ...
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>
pageLoad = function ()
{
    // Works great: no infinite loop, GridView paging works, embedded.Visible=false hides the grid
    __doPostBack("<%= embedded.ClientID %>");   

    // All of the problems
    $("#grid").update();                        
}
pageLoad(); 
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GridControl.ascx.cs" Inherits="Control" %>
<script type="text/javascript">
    var upClientID = "<%= updatePanel.ClientID %>";

    // Trigger the post-back so that the update panel re-loads data. 
    $.fn.update = function ()
    {
        __doPostBack(upClientID);
    };
</script>

<!-- Exactly the same as the embedded UpdatePanel -->
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:GridView ID="gridView"runat="server" AllowPaging="true" OnPageIndexChanging="gridView_PageIndexChanging">
            <Columns>
                ...
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

...
MainPage.js:

<%@ Register TagPrefix="test" TagName="GridControl" Src="~/Controls/GridControl.ascx" %>

<asp:ScriptManager ID="SM" runat="server" EnablePageMethods="true">

<test:GridViewControl ID="child" runat="server" />

<asp:UpdatePanel ID="embedded" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:GridView runat="server" AllowPaging="true" OnPageIndexChanging="gridView_PageIndexChanging">
            <Columns>
                ...
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>
pageLoad = function ()
{
    // Works great: no infinite loop, GridView paging works, embedded.Visible=false hides the grid
    __doPostBack("<%= embedded.ClientID %>");   

    // All of the problems
    $("#grid").update();                        
}
pageLoad(); 
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GridControl.ascx.cs" Inherits="Control" %>
<script type="text/javascript">
    var upClientID = "<%= updatePanel.ClientID %>";

    // Trigger the post-back so that the update panel re-loads data. 
    $.fn.update = function ()
    {
        __doPostBack(upClientID);
    };
</script>

<!-- Exactly the same as the embedded UpdatePanel -->
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:GridView ID="gridView"runat="server" AllowPaging="true" OnPageIndexChanging="gridView_PageIndexChanging">
            <Columns>
                ...
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>
pageLoad=函数()
{
//非常有用:没有无限循环,GridView分页有效,嵌入。Visible=false隐藏网格
__doPostBack(“”);
//所有的问题
$(“#网格”).update();
}
页面加载();
ChildControl.ascx:

<%@ Register TagPrefix="test" TagName="GridControl" Src="~/Controls/GridControl.ascx" %>

<asp:ScriptManager ID="SM" runat="server" EnablePageMethods="true">

<test:GridViewControl ID="child" runat="server" />

<asp:UpdatePanel ID="embedded" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:GridView runat="server" AllowPaging="true" OnPageIndexChanging="gridView_PageIndexChanging">
            <Columns>
                ...
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>
pageLoad = function ()
{
    // Works great: no infinite loop, GridView paging works, embedded.Visible=false hides the grid
    __doPostBack("<%= embedded.ClientID %>");   

    // All of the problems
    $("#grid").update();                        
}
pageLoad(); 
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GridControl.ascx.cs" Inherits="Control" %>
<script type="text/javascript">
    var upClientID = "<%= updatePanel.ClientID %>";

    // Trigger the post-back so that the update panel re-loads data. 
    $.fn.update = function ()
    {
        __doPostBack(upClientID);
    };
</script>

<!-- Exactly the same as the embedded UpdatePanel -->
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:GridView ID="gridView"runat="server" AllowPaging="true" OnPageIndexChanging="gridView_PageIndexChanging">
            <Columns>
                ...
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

var-upClientID=“”;
//触发回发,以便更新面板重新加载数据。
$.fn.update=函数()
{
__doPostBack(upClientID);
};
...
实际上,我在使用这个子控件时遇到了很多问题-设置Visible属性没有任何作用,GridView分页不起作用。。。创建一个简单的子控件竟然如此困难,这让我感到惊讶。

(回答我自己的问题)

虽然没有解决这个问题,但我最终将UpdatePanel嵌入到主页中,并将GridView提取为子控件。仍然有一些重复的代码,但是回发开始正常工作