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 7846329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:32:55+00:00 2026-06-02T17:32:55+00:00

I am creating Web User Controls via code (my C# code write-out markup, code-behind

  • 0

I am creating Web User Controls via code (my C# code write-out markup, code-behind and designer files to disk on a callback). The controls are created all fine. I can add them to my web-project and put them on a page.

When I try to load the control using LoadControl(path) it says:

Unable to load type 'MyNameSpace.UseControlClass'

which is because control is not yet compiled.

But my requirement is to load controls dynamically without recompiling the solution.

How can I compile the user control only when I create the control files? As this seems to be the only way out.

EDIT:- What my guess is that as the file is not compiled yet it is not allowed to be loaded by runtime. I have tried to compile the code file using CodeDom compiler. Like:

var filePath = Server.MapPath(path);
var provider = CSharpCodeProvider.CreateProvider("C#");
var opts = new CompilerParameters(new[] { "mscorlib.dll", "System.Web.dll", 
                              "Telerik.Web.Design.dll", "Telerik.Web.UI.dll", 
                              "Telerik.Web.UI.Skins.dll", "MyCurrentDll.dll"});
opts.GenerateExecutable = false;
opts.GenerateInMemory = true;
var cr = provider.CompileAssemblyFromFile(opts, new string[] { filePath+".cs" });

But it complains about cannot find metadata file Telerik.Web.Design.dll etc. I don’t want to hardcode the telerik path as it might be different in hosted system (though it is in the bin of current web app). Also MyCurrentDll.dll is the dll of the file from which I’m compiling the code file. How can I resolve this?

My idea is to compile the code file create a dll dynamically and copy it to web application’s bin directory. It might solve the problem I originally stated.

EDIT 2:- After hit and trial I am able to compile the code file dynamically and generate the dll. Even after generating dll and placing it into bin of my application I am not able to load user control using virtual path. I have tried the following approach:

var asm = Assembly.Load("ddlPath");
var t = asm.GetType(fullTypeName);//NameSpace.Class
var ctrl = LoadControl(t,null);

The ctrl is loaded after this. I assign its Id property and add it to an asp.net Panel control. But it is not visible after the postback 🙁

Now I either have to make somehow the dynamically compiled dll’s types available to the runtime (appdomain, maybe) so that when I load control using virtual path it is properly loaded and I don’t get HtmlParseException or figure out why loading control form Type is not showing up.

PS:- I have loaded a Label control using Type and it is working properly.

  • 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-06-02T17:32:58+00:00Added an answer on June 2, 2026 at 5:32 pm

    In the end I was able to resolve the problem. Following is the strategy I adopted:

    1. Create text files containing structure of CodeBehind, Markup and Designer code
    2. Read the information as to what fields to create.
    3. Put markup for controls needed in string builders.
    4. put some other related information into more string builders
    5. Write files

    After this I created the dll using CodeDome compiler. The main problem faced during compilation, as described in Edit part of question, was not finding referenced assemblies, which was resolved by putting path of bin directory’s path along with dll file name like:

    Server.MapPath("~/bin")+"\\Telerik.Web.dll"
    

    etc.

    Next problem outlined in EDIT2 was bit simpler. There was rather moronic. There was some problem in another user control embedded in dynamically generated user control.

    Even after this i was not able to load the control into the page from where I compiled the code. This was resolved when I loaded the control in another page. The runtime was able to resolve the type from dynamically compiled dll.

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

Sidebar

Related Questions

I've created a C# WinForms application using VS2010. I'm new to creating user controls
I'm creating a set of Web User Controls which will share a common base
I'm creating a web application on Google AppEngine where I want the user to
I am interested in creating a simple web application that will take in user
I'm creating a web page, and I can't (with html code) add a draw
I'm creating a comments web user control. I want to use this comments control
I am creating a web user control for showing Alert on AspxGridView Columns(Delete/Edit) click
I have simple web user control (the code I found somewhere in the web):
I'm creating a web app with various classes for things like the user, Smarty
I'm creating a simple web application with which a user may author a message

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.