I was creating a very simple page to play around with the Update Panel when I came across a weird error.
The page uses an Asynchronous post back trigger on an update panel to control the updating of the panel. Seems simple enough but I ran into trouble. The code I tried to run is below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:Label ID="Label1" runat="server" Text="Label" Width="300"></asp:Label> <asp:UpdatePanel ID="MyPanel1" runat="server"> <ContentTemplate> <p> <hr /> <asp:Label ID="Label2" runat="server" Text="Label" Width="300"></asp:Label> <hr /> </p> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="MyButton" EventName="Click" /> </Triggers> </asp:UpdatePanel> <p> <asp:Label ID="Label3" runat="server" Text="Label" Width="300"></asp:Label> </p> <p> <asp:Label ID="Label4" runat="server" Text="Label" Width="300"></asp:Label> </p> <asp:Button runat="server" ID="MyButton" OnClick="MyButton_Click" Text="click me" /> </div> </form> </body> |
1 2 3 4 5 6 7 8 9 10 11 12 |
protected void Page_Load(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToString(); Label2.Text = DateTime.Now.ToString(); Label3.Text = DateTime.Now.ToString(); Label4.Text = DateTime.Now.ToString(); } protected void MyButton_Click(object sender, EventArgs e) { } |
When I ran the code above I received a weird error from Visual Studio.
I did some digging and found the offending code to be the paragraph tags “<p>” and “</p>” inside the ContentTemplate tags. Removing the paragraph tags allowed me to run the code without error and continue to play!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:Label ID="Label1" runat="server" Text="Label" Width="300"></asp:Label> <asp:UpdatePanel ID="MyPanel1" runat="server"> <ContentTemplate> <hr /> <asp:Label ID="Label2" runat="server" Text="Label" Width="300"></asp:Label> <hr /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="MyButton" EventName="Click" /> </Triggers> </asp:UpdatePanel> <p> <asp:Label ID="Label3" runat="server" Text="Label" Width="300"></asp:Label> </p> <p> <asp:Label ID="Label4" runat="server" Text="Label" Width="300"></asp:Label> </p> <asp:Button runat="server" ID="MyButton" OnClick="MyButton_Click" Text="click me" /> </div> </form> </body> |