Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 239211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:34:02+00:00 2026-05-11T20:34:02+00:00

I’m referencing the article reference To create a UserControl dynamically and pass it back

  • 0

I’m referencing the article reference

To create a UserControl dynamically and pass it back to a page via jQuery.

When I just do a simple text in the UserControl “Hello World” everything works great… however, when I tried putting interactive controls on the control, I got the following message in my WebMethod (so the jQuery call stuff is irrelevant) (further testing showed that textboxes, and buttons cause the issue, but not labels)

Error executing child request for handler ‘System.Web.UI.Page’

here’s the webmethod:

[WebMethod]
public static string GetCtrl(string cname)
{
    StringWriter sw = new StringWriter();

    Page p = new Page();
    Control c = p.LoadControl("~/Controls/" + cname);
    p.Controls.Add(c);

    try
    {
        HttpContext.Current.Server.Execute(p, sw, false);
    }
    catch (Exception err)
    {
        return err.Message;
    }
    sw.Close();

    return sw.ToString();
}

The exception is happening during the Server.Execute call.

A solution may not be possible, I’d just like to know why interactive controls cause this.

EDIT:
Taking advice below I looked deeper and found the inner exception said something to the effect that it must be within a form tag marked with runat=”server”, while I’m displaying this control on a aspx page within the form tag… my guess is that there’s got to be some sort of ‘asp.net magic’ connection there for the control to operate… regardless, it’d be nice to know how to render a page with controls on it anyway (even if it wasn’t usable in this situation)

So I looked at the output of the above code and for those curious:

<span id="ctl00_lbl1">abc: </span>

So the control is rendering properly (with just the label id=’lbl1′) on the page, however, the control is itself rendered, and the page content is not there at all… Is there a way to generate the page source as well? (I must not understand the way the Server.Execute function works)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:34:02+00:00Added an answer on May 11, 2026 at 8:34 pm

    I’d start by narrowing down the problem. For instance, what happens if you leave off the

    p.Controls.Add(c);
    

    What happens if you properly implement a using statement?

    using (StringWriter sw = new StringWriter()) {
        // ...
        HttpContext.Current.Server.Execute(p, sw, false);
        return sw.ToString();
    }
    

    What happens, if you leave off the try/catch? It’s costing you all the information in the exception other than the Message property, so why not just leave it off? Your caller might be expecting HTML in any case, so if you keep it, you might (later) want to wrap the output:

    return "<p>" + ex.ToString() + "</p>";
    

    Little by little, remove things until the problem goes away.


    Based on what you learned from the InnerException, I recommend that you add an HtmlForm control to the page, then add your loaded control as a child control of the HtmlForm.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The xterm which Apple ship with OS X appears to… May 11, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer Firstly, it is a good idea to use SPs, rather… May 11, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer Well you could open your entire MYSQL socket so that… May 11, 2026 at 11:52 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.