【问题标题】:Entire webpage still refreshes despite using update panel尽管使用更新面板,整个网页仍会刷新
【发布时间】:2017-04-09 15:20:01
【问题描述】:

好的,现在我遇到的问题是,虽然我正在使用更新面板,但每当我在更新面板中更新任何内容时,整个网页都会刷新。

这里是代码

 <div id="firstbar">
          <asp:UpdatePanel ID="UpdatePanel1" runat="server"  >
                <ContentTemplate>    
        <div style="width:15%;float:left;">

            <asp:Image ID="Image1" runat="server" ImageUrl="~/Img/Untitled1.png" CssClass="imagez" />

        </div>
         </ContentTemplate>

        <div style="width:85%;float:left;height:100%;padding-top:2%;">

            <asp:Label ID="Label2" runat="server" Text="CPU" CssClass="auto-style7" Font-Names="sans-serif"></asp:Label>
            <br />

            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" CssClass="bla" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Name" Font-Names="sans-serif" AppendDataBoundItems="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
    <asp:ListItem Selected="True">Pick a CPU</asp:ListItem>
    </asp:DropDownList>
            <asp:UpdatePanel ID="UpdatePanel17" runat="server">
            <ContentTemplate>

            <strong>

            <asp:Label ID="Label3" runat="server" Text="$" CssClass="auto-style8" Font-Names="sans-serif"></asp:Label>
                <asp:Label ID="Label4" runat="server" Text="0.00" CssClass="auto-style8" Font-Names="sans-serif"></asp:Label>
            </strong>

        </div>
            </ContentTemplate>
               </asp:UpdatePanel>

    </div>

【问题讨论】:

标签: c# asp.net


【解决方案1】:

您的更新面板仅包含非交互式控件(标签和图像),而交互式项目(如自动回发下拉列表)位于更新面板之外。只有在更新面板内部启动的回发才会导致部分回发。因此,您必须将这些控件移动到更新面板中。例如下拉列表:

<div style="width:85%;float:left;height:100%;padding-top:2%;">

            <asp:Label ID="Label2" runat="server" Text="CPU" CssClass="auto-style7" Font-Names="sans-serif"></asp:Label>
            <br />

            <asp:UpdatePanel ID="UpdatePanel17" runat="server">
            <ContentTemplate>
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" CssClass="bla" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Name" Font-Names="sans-serif" AppendDataBoundItems="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
    <asp:ListItem Selected="True">Pick a CPU</asp:ListItem>
    </asp:DropDownList>

            <strong>

            <asp:Label ID="Label3" runat="server" Text="$" CssClass="auto-style8" Font-Names="sans-serif"></asp:Label>
                <asp:Label ID="Label4" runat="server" Text="0.00" CssClass="auto-style8" Font-Names="sans-serif"></asp:Label>
            </strong>

        </div>
            </ContentTemplate>
               </asp:UpdatePanel>
</div>

【讨论】:

  • 这样做,我会得到这个错误 Uncaught Error: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.
  • 检查异常的堆栈跟踪,这是非 .NET 异常中的 NullReferenceException 的文本。检查任何内部异常的堆栈跟踪。您描述的问题很可能与更新面板无关。您可能必须单步执行您的事件处理程序。
  • 这是我不断收到的错误:在 Function.Error$create [as create] (localhost:58930/ScriptResource.axd?
猜你喜欢
  • 1970-01-01
  • 2010-09-07
  • 1970-01-01
  • 1970-01-01
  • 2011-05-19
  • 2013-04-15
  • 1970-01-01
  • 1970-01-01
  • 2014-03-09
相关资源
最近更新 更多