Note that there are some explanatory texts on larger screens.

plurals
  1. POTextBoxes in UpdatePanel are causing PageRequestManagerServerErrorException
    primarykey
    data
    text
    <p>I'm trying to create a page that has some information in databound labels with and edit button. When the edit button is clicked, the information is replaced with TextBoxes bound to the same data. The data can then be modified, saved back to the DB and the TextBoxes replaced with updated Labels.</p> <p>To start with, and to keep things simple, all I have is an <code>UpdatePanel</code> with a <code>DataList</code> and two buttons: <code>EditButton</code> and <code>CancelButton</code> (<code>CancelButton</code> is hidden by default). The <code>DataList</code>'s <code>ItemTemplate</code> has two Panels: <code>ViewPanel</code> and <code>EditPanel</code> (<code>EditPanel</code> is hidden by default). When <code>EditButton</code> is clicked, I hide <code>EditButton</code> and the <code>DataList</code>'s <code>Items</code>' <code>ViewPanel</code>, and show <code>CancelButton</code> and the <code>DataList</code>'s <code>Items</code>' <code>EditPanel</code>.<br> Not a problem. Once this is done however, the <code>CancelButton</code> button will not work, throwing a <code>PageRequestManagerServerErrorException</code>.</p> <p>Through some fiddling, I worked out this happens because there are databound text boxes on the <code>EditPanel</code>. If I don't bind data to the text boxes, everything works perfectly. Why doesn't this work?</p> <p>Here's my code:</p> <p>UpdatePanelTest.aspx</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UpdatePanelTest.aspx.cs" Inherits="WebLetterViewer.UpdatePanelTest" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"&gt;&lt;/asp:ScriptManager&gt; &lt;asp:SqlDataSource ID="AllLettersDataSource" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ORMSTestConnectionString %&gt;" SelectCommand="SELECT * FROM [Letters] WHERE ([id] = @id)"&gt; &lt;SelectParameters&gt; &lt;asp:ControlParameter ControlID="HiddenLetterID" DefaultValue="1" Name="id" PropertyName="Value" Type="Int32" /&gt; &lt;/SelectParameters&gt; &lt;/asp:SqlDataSource&gt; &lt;asp:HiddenField ID="HiddenLetterID" runat="server" Value="1" /&gt; &lt;div&gt; &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false"&gt; &lt;ContentTemplate&gt; &lt;asp:DataList ID="LettersDataList" runat="server" DataSourceID="AllLettersDataSource"&gt; &lt;ItemTemplate&gt; &lt;asp:Panel ID="ViewPanel" runat="server"&gt; &lt;h2&gt;Data1:&lt;/h2&gt; &lt;asp:Label ID="data1Label" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="100px" Text='&lt;%# Eval("data1") %&gt;' Width="500px" /&gt; &lt;h2&gt;data2:&lt;/h2&gt; &lt;asp:Label ID="data2Label" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="100px" Text='&lt;%# Eval("data2") %&gt;' Width="500px" /&gt; &lt;h2&gt;data3:&lt;/h2&gt; &lt;asp:Label ID="data3Label" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="100px" Text='&lt;%# Eval("data3") %&gt;' Width="500px" /&gt; &lt;/asp:Panel&gt; &lt;asp:Panel ID="EditPanel" runat="server" Visible="False"&gt; &lt;h2&gt;data1:&lt;/h2&gt; &lt;asp:TextBox ID="data1TextBox" runat="server" Height="100px" Text='&lt;%# Eval("data1", "{0}") %&gt;' TextMode="MultiLine" Width="500px"&gt;&lt;/asp:TextBox&gt; &lt;h2&gt;data2:&lt;/h2&gt; &lt;asp:TextBox ID="data2TextBox" runat="server" Height="100px" Text='&lt;%# Eval("data2", "{0}") %&gt;' TextMode="MultiLine" Width="500px"&gt;&lt;/asp:TextBox&gt; &lt;h2&gt;data3:&lt;/h2&gt; &lt;asp:TextBox ID="data3TextBox" runat="server" Height="100px" Text='&lt;%# Eval("data3", "{0}") %&gt;' TextMode="MultiLine" Width="500px"&gt;&lt;/asp:TextBox&gt; &lt;/asp:Panel&gt; &lt;/ItemTemplate&gt; &lt;/asp:DataList&gt; &lt;asp:Button ID="EditButton" runat="server" onclick="EditButton_Click" Text="Edit" /&gt; &lt;asp:Button ID="CancelButton" runat="server" onclick="CancelButton_Click" Text="Cancel" Visible="False" /&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>UpdatePanelTest.aspx.cs</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebLetterViewer{ public partial class UpdatePanelTest : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e){ } protected void EditButton_Click(object sender, EventArgs e){ foreach (DataListItem item in LettersDataList.Items){ item.FindControl("ViewPanel").Visible = false; item.FindControl("EditPanel").Visible = true; } EditButton.Visible = false; CancelButton.Visible = true; UpdatePanel1.Update(); } protected void CancelButton_Click(object sender, EventArgs e){ foreach (DataListItem item in LettersDataList.Items){ item.FindControl("ViewPanel").Visible = true; item.FindControl("EditPanel").Visible = false; } EditButton.Visible = true; CancelButton.Visible = false; UpdatePanel1.Update(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload