Patrick Wright's Blog RSS 2.0
# Saturday, December 12, 2009
del.icio.us Tags: ,

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.

image

 

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>

Saturday, December 12, 2009 4:41:00 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
code
Categories
 
Archive
<December 2009>
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2012
Patrick Wright
Sign In
Statistics
Total Posts: 2
This Year: 0
This Month: 0
This Week: 0
Comments: 1
All Content © 2012, Patrick Wright