Ajax PageRequestManagerParserErrorException with a Response.Write

I’ve been messing around with Ajax for a new site I’m working on, and my page requires an UpdatePanel control.  Inside the UpdatePanel, I have a LinkButton, and since I was just testing to make sure my functionality was functioning (who wants nonfunctioning functionality, right?), I added this code to make sure all was well in the world of Ajax postbacking, and such:

        protected void btnViewRuns_Click(object sender, EventArgs e)
        {
            Response.Write("Howdy");
        }

So I click the button and blammo! I get this:

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed

The problem is that I had put that Response.Write in my click event. Apparently, that is not a welcome piece of code when dealing with an UpdatePanel. Removing it and putting in a Label control to hold my testing messages was sufficient. In case you are wondering, my final awesome code looked like this:

        <asp:UpdatePanel ID="pnlMain" runat="server">
            <ContentTemplate>
                        <asp:LinkButton ID="btnView" Text="Vie" runat="server"    onclick="btnView_Click" />
                        <asp:Label ID="lblTest" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>

Code behind:

        protected void btnView_Click(object sender, EventArgs e)
        {
            lblTest.Text = "Howdy";
        }

The wonder of it all.

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: