Registering UserControl in codebehind receives parser error exception on calendar click

Posted on 2011-05-08
Last Modified: 2012-05-11
I have a control registered on a page using;

<%@ Register Src="~/Controls/33pd.ascx" TagName="pd" TagPrefix="pd3" %> at the top of the page and
<pd3:pd id="pd" runat="server"></pd3:pd> where I need the control to be displayed

Which all works fine and no issues the control includes a grid view and tabconatiners displaying data and another control with a asp:calendar displaying data from a database inside an updatepanel.

I need to be able to add the 33pd.ascx control dynamically from the codebehind so I can display different versions of the 33pd.ascx.

I have this code which displays the different controls and loads the controls on the page;
            Control uc = null;

                if (dsPropCheck.Tables[0].Rows[0]["Source"].ToString() == "33")
                    uc = Page.LoadControl(Request.ApplicationPath + "/Controls/33pd.ascx");
                    else if (dsPropCheck.Tables[0].Rows[0]["Source"].ToString() == "22")
                        uc = Page.LoadControl(Request.ApplicationPath + "/Controls/22pd.ascx");
                    else if (dsPropCheck.Tables[0].Rows[0]["Source"].ToString() == "11")
                        uc = Page.LoadControl(Request.ApplicationPath + "/Controls/11pd.ascx");

on page placeholder;
    <asp:PlaceHolder ID="PHPD" runat="server"></asp:PlaceHolder>

but when I click to intereact with the calendar I get this error;

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.6; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 1.1.4322; InfoPath.2; .NET4.0C)
Timestamp: Sun, 8 May 2011 11:20:30 UTC

Message: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near '
<!DOCTYPE html PUB'.

Question by:chrispaton
    LVL 11

    Accepted Solution

    That's an ajax/updatepanel client side error indicating that something is screwy with the response.  My recommendation is to look at the response that comes back with fiddler (  There's other ways to see the response too but fiddler is the easiest one IMO.

    I beleive you could also try turning off partial page rendering and you might get a more specific error message:

    Assisted Solution

    Fiddler is a nice tool to have, I used this on the page but was not highlighting any issues with the page all loading fine, and nothing coming back when I clicked on the calendar.

    Did some more testing and found the problem was I had my code to do the database check to return the different controls within if (!IsPostBack).

    Moved the check before the if (!IsPostBack) and the calendar worked fine but this gave me major issues with other jquery tools on the page that had worked previously to trying to add the controls dynamically, all working now.

    Author Closing Comment

    The Fiddler tool was a useful tool to use/suggest for the problem but this did not highlight any issues relating to the problem and found the solution to the problem myself with some more checks after eliminating that all the elements on the page were loading using the tool suggested

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now