del.icio.us Tags:
code,
ajax 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.
<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>
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!
The new code is below.
<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>