Welcome to MSDN Blogs Sign in | Join | Help

Turning an ascx user control into a redistributable custom control

This article applies to ASP.NET 2.0 and Visual Studio 2005.

Background

Since its early days, ASP.NET has always supported two different ways of authoring server controls:

  1. Custom Controls: these are controls written from scratch exclusively using code.  Essentially, you write a class which extends Control (directly or indirectly), and you take care of everything.  You need to write logic to create child controls that you want to use, and you override the Render method to perform rendering.  Typically, you build this control into a redistributable assembly (i.e. a DLL), which can then be used by any ASP.NET applications, simply by placing the assembly in the 'bin' directory of the app (or in the Global Assembly Cache).
  2. User Controls: these control are written using an ascx file, which looks much like an aspx page.  i.e. you can simply drag and drop the UI elements that you want to use into the design surface.  You don't need to worry about control creation, nor about overriding the Render method.

Looking at those two methods, they are very different, and each has a number of advantages and disadvantages.  I won't discuss them all, but will focus on those that are relevant to this article:

  • Custom Controls require a lot of development expertise to be written, while User Controls are authored using an advanced designer, and are much more approachable.  For this reason, User Controls typically take a lot less time to write.
  • Custom Controls can easily be redistributed without having to give away their sources.  On the other hand, User Controls are always used based on an ascx text file, making it less ideal for reuse across applications.

The goal of this article is to show how you can have the best of both world by turning an ascx user control into a redistributable custom control, by making use of ASP.NET 2.0's new precompilation features.

 

Brief outline of the steps

The basic steps to make this happen are as follows:

  1. Write your User Control as you normally would, typically using the Visual Studio designer.
  2. Test it using a simple page before trying to deploy it.
  3. Deploy the app to precompile it.
  4. Grab the user control's assembly produced by the deployment step, and you're essentially done: you have your Custom Control.
  5. Finally, use your Custom Control in other apps the same way as you always use Custom Control's.
We will look at those steps in more detail in the rest of the article.
 

Step 1: Authoring the User Control

To author the User Control, it is best to start with an empty app that contains nothing other than the ascx.  While the authoring of the User Control uses 'standard' techniques, there are some restrictions that you need to be aware of in order for it to be successfully turned into a standalone Custom Control.

The main restriction is that the User Control needs to be self contained.  That is, it cannot be dependent on app global things like App_Code or global.asax.  The reason for this is that since the goal is to turn the UserControl into a standalone DLL, it would break in other apps if it relied on code that is not part of that DLL.

One exception to this rule is that the UserControl can be dependent on assemblies that live in the bin directory (or in the GAC).  You just have to make sure that the other assemblies are always available when you use your Custom Control in other apps.

Another tricky thing is the use of static resources, like images.  After you turn it into a Custom Control in a standalone assembly, it becomes hard for it to keep such references, and avoiding them simplifies deployment.  If you really must have such references, one option is to use absolute URL's if you can guarantee that the resource will always be available on a certain site.  Or you can look into machine wide resources (e.g. src="/MyImages/welcome.jpg"), though you will then need to make sure the resources are installed on the server machine (e.g. as part of some setup).

Ok, so let's start and actually author the User Control.  Visual Studio 2005 gives you the choice to place the code in a separate file, or use inline code.  This is a matter of personal preference, and either one will work to create a Custom Control.  For this article, we will use inline code.  When you create the User Control (say MyTestUC.ascx), VS creates it with the a @control directive that looks like this:

<%@ Control Language="C#" ClassName="MyTestUC" %>

This is fine, except for one thing: we want the class to live within a namespace of our choice (instead of 'ASP', which is what's used by default).  To do this, we simply modify the ClassName attribute to include the namespace (this is a new feature in 2.0).  e.g.

<%@ Control Language="C#" ClassName="Acme.MyTestUC" %>

That's really the only 'special' thing you need to do.  Now you can go ahead and implement your User Control as you always would: add some server control, some client HTML, server script, client script, etc...

 

Step 2: Testing your User Control

Before trying to turn the User Control into a Custom Control, it is a good idea to test it in the source app using a simple page.  To do this, simply create a new Page in Visual Studio, go to design View, and drag and drop your User Control into it.

The two notable pieces of your page are the Register directive:

<%@ Register Src="MyTestUC.ascx" TagName="MyTestUC" TagPrefix="uc1" %>

and the User Control declaration:

        <uc1:MyTestUC ID="MyTestUC1" runat="server" />

Note that at this point, the Register directive uses the User Control syntax (Src/TagName/TagPrefix) and not the Custom Control syntax (TagPrefix/Namespace/Assembly).  This will change after we turn the User Control into a Custom Control.

Run your page (Ctrl-F5) and make sure the User Control works the way you want before moving to the next step.


Step 3: Use the Publish command to precompile the site

The next step is to use the new Publish command to precompile your site and turn your User Control into a potential Custom Control.  You'll find the command under Build / Publish Web Site.  In the Publish dialog, do the following:

  • Pick a Target Location.  This is the location on your hard drive that your site will be precompiled to.
  • Uncheck 'Allow this precompiled site to be updatable'.  In updatable mode, only the code behing file (if any) would get compiled, and the ascx would be left unprocessed.  This is useful in some scenarios, but is not what you want here since you want the resulting DLL to be self contained.
  • Check 'Use fixed naming and single page assemblies'.  This will guarantee that your User Control will be compiled into a single assembly, which will have a name based on the ascx file.  If you don't check this, your User Control could be compiled together with other pages and User Controls (if you had some), and the assembly would get a random name that would be more difficult to work with.

Though it is entirely optional, note that the Publish Web Site dialog lets you strong name the generated assemblies.  This allows you to sign the assembly so that it cannot be tempered with.  Additionally, it allows you to place the assemblies in the Global Assembly Cache (GAC), which makes it easier to use machine wide.  More on this in Step 5.

Go ahead and complete the dialog, which will perform the precompilation.

Note: This same step can also be accomplished without using Visual Studio by using the new aspnet_compiler.exe command line tool.  The options it supports are basically the same as what you see in the Publish dialog.  So if you are more command line inclined, you might prefer that route.  e.g. you would invoke it using the command: 'aspnet_compiler -p c:\SourceApp -v myapp -fixednames c:\PrecompiledApp'.

 

Step 4: finding the resulting Custom Control

Now, using the Windows Explorer or a command line window, let's go to the directory you specified as the target so we can see what was generated.  You will see a number of files in there, but let's focus on the one that is relevant to our goal of turning the User Control into a Custom Control.

In the 'bin' directory, you will find a file named something like App_Web_MyTestUC.ascx.cdcab7d2.dll.  You are basically done, as this file is your User Control transformed into a Custom Control!  The only thing that's left to do is to actually use it.

Note: In case you're curious, the hex number within the file name (here 'cdcab7d2') is a hash code that represents the directory that the original file was in.  So all files at the root of your source app will use 'cdcab7d2', while files in other folders will use different numbers.  This is used to avoid naming conflicts in case you have files with the same name in different directories (which is very common for default.aspx!).

 

Step 5: Using your new Custom Control

Now that we have created our Custom Control, let's go ahead and use it in an app!  To do this, let's create a new Web application in Visual Studio.  We then need to make our Custom Control available to this application:

  • In the solution explorer, right click on your application, and choose Add Reference.
  • In the Add Reference dialog, choose the Browse tab.
  • Navigate to the location of your Custom Control (App_Web_MyTestUC.ascx.cdcab7d2.dll) and select it.  It will be copied to the bin directory of your new app.

Note: as an alternative, you can choose to place the assembly in the GAC instead of the 'bin' directory.  In order to do this, you need to choose the Strong Name option in Step 3.  You then need to add your assembly in the <assemblies> section of web.config in the Web application that wants to use it (or in machine.config to make to globally usable).

Now let's create a test page that uses the Custom Control.  This is similar to Step 2, except that you are now dealing with a Custom Control instead of a User Control.

First, add a Register directive to your page.  It should look something like this:

<%@ Register TagPrefix="Acme" Namespace="Acme" Assembly="App_Web_mytestuc.ascx.cdcab7d2" %>

Note how we are using a different set of attributes compared to Step 2.  Recall that in Step 1, we made sure that the ClassName attribute included a namespace.  This is where it becomes useful, as Custom Control registration is namespace based.  Also, you need to specify the assembly name, which is why having a name that is easily recognizable is useful, as discussed in Step 3.

Now, let's declare a tag for the Custom Control.  e.g.

    <Acme:MyTestUC id="MyUC" runat="server" />

That's it, you can now run your app (Ctrl-F5), and you are using your new Custom Control!

This shows how to use your Custom Control declaratively, but note that it can also be used dynamically, just like any other control.  To do this, just create the control using 'new'.  Here is what the previous sample would look like using dynamic instantiation:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
protected void Page_Load(object sender, EventArgs e) {
        Label1.Controls.Add(
new Acme.MyTestUC());
    
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    
<form id="form1" runat="server">
    
<div>
        
<asp:Label ID="Label1" runat="server"></asp:Label></div>
    
</form>
</body>
</html>

 

Note: instantiating your Custom Control dynamically as above is basically the equivalent of instantiating your original User Control using the LoadControl API.  Note that you can no longer use the standard LoadControl API after converting it to a Custom Control, since Custom Controls don't have a virtual path.  However, ASP.NET 2.0 has a new LoadControl override which takes a Type, and that you could use in this case.  The one reason I can think of that you might choose to call LoadControl instead of just using 'new' is to take advantage of fragment caching (aka partial caching).  If you use 'new', any OutputCache directive in your ascx will be ignored.

 

Conclusion

This article outlines how to turn a User Control into a Custom Control, in order to take advantage of the strength of each model.  While there are some limitations with this hybrid model (see Restrictions in Step 1), there are many scenarios for which it can be useful.

In the future, the ASP.NET team is looking at simplifying this scenario and make it more powerful with some new tools that are in the work.  For example, you would be able to take an entire application containing an App_Code directory and multiple User Control, and turn it all into a single assembly that can easily be dropped into the 'bin' directory of other apps.  Though it will allow some more powerful scenarios, note that the basic idea behind it is essentially the same as what is shown in this article.

Published Sunday, October 30, 2005 11:35 PM by davidebb
Filed under:

Comments

# re: Turning an ascx user control into a redistributable custom control

Thanks for the nice article. K. Scott Allen wrote something similar at

http://odetocode.com/Blogs/scott/archive/2005/10/06/2326.aspx

He also enhanced the msbuild-file to use ilmerge to merge all the dll's.
Maybe the tool released by the ASP.NET team will be even more powerful?
Monday, October 31, 2005 3:28 AM by Steinar Herland

# re: Turning an ascx user control into a redistributable custom control

Steinar, the tool I was referring to is actually available now in beta form, and is called "Visual Studio 2005 Web Deployment Projects". More specifically, it contains a tool named aspnet_merge.exe. Here is the link:

http://msdn.microsoft.com/asp.net/reference/infrastructure/wdp/default.aspx

It's probably the same general idea as the link your comment points to.
Tuesday, November 29, 2005 4:16 PM by davidebb

# re: Turning an ascx user control into a redistributable custom control

Hi,

Just made a UserControl with three objects (calendar, textbox, button),
a public method and property. Nothing fancy; just a 'stupid' User
Control. The control appears on my test aspx page.
Compiled it in such a way that Visual Studio 2005 generates an assembly
for the User Control, as described in your article.

After that I added a reference to this assembly in another solution.
There I can reference to my User Control without any problems.
After running the page with this UserControl the control is not
appearing. Method and property of the User Control work fine.
However the values for the three child objects are null. For that
reason of course I can't see the control.
But why are these controls null?
Any idea?

Kind regards,

Michel
Thursday, February 02, 2006 1:57 AM by Michel

# re: Turning an ascx user control into a redistributable custom control

Hi Michel,

I am facing the same problem as u described.
Did u find any work around? If yes then Please post here.

Thanks and Regards,
Maahee
Wednesday, February 08, 2006 7:44 AM by Maahee

# re: Turning an ascx user control into a redistributable custom control

Having the same problem, please let me know if a fix is found!
Wednesday, February 08, 2006 9:08 AM by Richard Cresswell

# re: Turning an ascx user control into a redistributable custom control

I have created the same.
Created a user control and generated its dll -the assembly after using Publish Web Site command.
Then I am using this dll and its user control.
I have used the register tag in My test project as given in this article but that gives me the error as User control not found inspite of adding reference of the dll .

Thanks
Swati
Wednesday, February 08, 2006 9:08 AM by Swati

# re: Turning an ascx user control into a redistributable custom control

Hi David,

I know you posted this a while back but I have just started playing with this (it solves a problem we have quite nicely).

One issue that I have come across is that if you place the compiled UserControl into another UserControl (rather than onto a web page), when you view the web page (that contains the second, uncompiled, user control)at design-time, the UserControl is rendered with an error ("Object Reference not set to an instance of an object").

This doesn't affect the runtime behaviour (which renders/runs everything correctly) but it does look a little messy at design-time.

This is nothing I can't live with (just means the uncompiled UserControl is basically rendered how it used to be - no UI) but I wondered if the team is planning on improving the design-time experience of a compiled usercontrol (both this as well as the fact that the compiled UserControl doesn't render it's UI when placed onto a page and you can't put a compiled usercontrol into the Toolbox)?
Wednesday, February 22, 2006 3:16 PM by Bryant

# re: Turning an ascx user control into a redistributable custom control

Hi! This post is specially for Michel, Maahee and Swati, in case they haven't figured their problem out meanwhile. I too created an user control with some basic server controls in it (a textbox, a label and a button) and it didn't show up. So I dissasembled the asembly of the custom controls to see what's wrong. As weird as it may sound but it seems that even in .NET 2.0 the inline code actually becomes a derived class of the code-behind (as was the case in 1.1) and NOT a single class comprised of two partial classes. So by registering the custom control with a <%@ Register TagPrefix="Acme" Namespace="Acme" Assembly="App_Web_mytestuc.ascx.cdcab7d2" %> and a <Acme:MyTestUC id="MyUC" runat="server" /> directive you actually invoke the base and not the derived class. To really invoke the rendering (derived) class ypu should. The solution is to use <%@ Register TagPrefix="Acme" Namespace="ASP" Assembly="App_Web_mytestuc.ascx.cdcab7d2" %> and <Acme:mytestuc_ascx id="MyUC" runat="server" /> or something like that, depending on the name of your UC. If you still don't get it, dissasemble the custom control and you'll see what I mean.
Kind regards,
Orlin
Wednesday, April 12, 2006 10:34 AM by Orlin Georgiev

# ASP.NET 2.0 - one month on

It's over a month now since Visual Studio 2005 officially RTM'd, and during that time I've been fortunate...
Tuesday, May 02, 2006 4:50 PM by Ian Nelson

# re: Turning an ascx user control into a redistributable custom control

Hi ! Thanks Orlin the soluation you told its working cool I have another question while I am compiling my program it is given me this error :

: CS0115: 'ASP.default_aspx.GetTypeHashCode()': no suitable method found to override

Source Error:

[No Relevant source lines]

DO u have any idea why it is so...

Thanks
Anuj
Wednesday, May 24, 2006 11:56 AM by Anuj

# re: Turning an ascx user control into a redistributable custom control

Anuj,

Have you tried following the steps exactly as outlines in the article?  Orlin's comment only applies if you are doing something different from the steps.  Specifically, make sure you are properly setting the classname attribute as explained in Step 1.

thanks,
David
Wednesday, May 24, 2006 12:12 PM by davidebb

# re: Turning an ascx user control into a redistributable custom control

Hi David,

  Thanks for this great article. I was facing the same problem as described by Michel. I made sure that I am properly setting the classname attribute as explained in Step 1, and everything worked fine, BUT ONLY IF I USE INLINE CODE.

  I want to use code-behind model, but I am not able to get that to work. When I add the "ClassName" attribute, I get the following error; -

 "Missing partial modifier on declaration of type 'Acme.MyTestUC'; another partial declaration of this type exists....c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ui\a00a88f8\c67bcb51\App_Web_nuzxcasf.0.cs 138"

 Kindly help. I am stuck :(

Thanks.
Friday, June 02, 2006 9:15 AM by Phcyso

# re: Turning an ascx user control into a redistributable custom control

Phcyso,

This hsould work fine with the code behind model.  Make sure your code behind ascx looks something like this:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CodeBesideControl.ascx.cs"
Inherits="Acme.CodeBesideControl" ClassName="Acme.MyCodeBesideControl" %>

and that the ascx.cs defines the matching partial class in the same namespace.

David
Friday, June 02, 2006 5:54 PM by davidebb

# re: Turning an ascx user control into a redistributable custom control

I've been trying this method. No success yet. Can you guys post a sample here?

Thanks.
Sunday, July 02, 2006 5:50 PM by Dave

# Turning an ascx user control into a redistributable custom control

David Ebbo has written an article about Turning an ascx user control into a redistributable custom control.The
Saturday, July 15, 2006 1:48 AM by Keyvan Nayyeri

# Turning an ascx user control into a redistributable custom control

David Ebbo has written an article about Turning an ascx user control into a redistributable custom control.The
Sunday, July 16, 2006 2:57 AM by Keyvan Nayyeri

# OK, Now how do you rename without breaking it.

I have a control: App_Web_simplecontrol.ascx.cdcab7d2.dll

I like to distribute it as simplecontrol.dll. but simpley renaming and replacing App_Web_simplecontrol.ascx.cdcab7d2 with simplecontrol on code doesn't work.

Any suggestions?
Tuesday, July 18, 2006 6:11 PM by Jared McGuire

# re: Turning an ascx user control into a redistributable custom control

Jared, I think you should be able to use ILMerge (available on MSDN) to do this. You could also use it to package multiple controls into one DLL.

David
Tuesday, July 18, 2006 6:23 PM by davidebb

# re: Turning an ascx user control into a redistributable custom control

I got the web deployment project to do it for me. This also lets me have multiple asxc files.

Now I have a new issue:
I can add the dll reference and manually add the register command and controls to the html. I would like to add this dll to the toolbox so that I can simply drag my controls to the form and have the reference, register, and html auto added, like other custom controls do. However the toolbox tells me that "there are no components that it can place in the toolbox".

Once this works then I will be golden!
Thursday, July 20, 2006 10:39 AM by Jared McGuire

# re: Turning an ascx user control into a redistributable custom control

Has anyone been able to drag and drop the created control from the toolbox?
Wednesday, September 06, 2006 8:56 AM by Toni Bailon

# re: Turning an ascx user control into a redistributable custom control

It's very useful, but is it possible to see the control inserted in a form?

Is it possible to see it at design time, like any other web control?
Wednesday, September 06, 2006 9:02 AM by Toni

# ASP.NET 2.0 - one month on

It's over a month now since Visual Studio 2005 officially RTM'd, and during that time I've been fortunate

Monday, December 04, 2006 12:02 PM by Ian Nelson

# re: Turning an ascx user control into a redistributable custom control

Hi there, I'm having some problems. I've done a web user control with a textbox wich i'll want to access from a page.

(Code .ascx)

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MFComment.ascx.cs" Inherits="MF.MFComment" %>

...(my code)....

(Code .ascx.cs)

namespace MF

{

   public partial class MFComment : System.Web.UI.UserControl

   {

...(my code)...

   }

}

- If I use the attribute ClassName inside the Control directive I get the following error:

Missing partial modifier on declaration of type 'MF.MFComment'; another partial declaration of this type exists c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\distributeascxcontrol\29b825f5\aaee677f\App_Web_wgindfuh.0.cs 138

When I publish the control (without the ClassName) everything goes well.

The problem begins when I want to use the published assembly.

I register the control and declare it on my page but i'm cannot see it when i run the page. I can access the control and it's properties from the page code behind but when I test my page the control does not appear.

(Code Page .aspx)

<%@ Register TagPrefix="MF" Namespace="MF" Assembly="App_Web_mfcomment.ascx.cdcab7d2" %>

...

<MF:MFComment ID="myctl" runat="server" />

...

Can anyone explain me what can be the problem and how to solve it?

Thanks in advance!

Monday, February 05, 2007 7:39 AM by Ricardo Gomes

# re: Turning an ascx user control into a redistributable custom control

This works great.

I had some trouble getting the compile-and-deploy to work using the 2-file method (code-infront and code-behind). The problem was that the control was not showing up on the page at all. It might have been a issue with the namepaces, casing, or something like that. I switched to the 1-file method and it worked fine. GEFN. I will refactor later if necessary.

Thank you VERY much.

-- Mark Kamoski

Thursday, February 08, 2007 1:48 PM by Mark Kamoski

# Cannot dynamically created control

Hello David,

I followed the steps that were shown, and for the most part, it is working.

In my usercontrol (example, NumericTextBoxControl) which wraps a normal TextBox web control, I exposed the embedded TextBox as a property (only Get).

I am now able to use the dlls that the Publish website created within another web site project’s ascx files by registering the dll and using the control within the HTML of my ascx pages.

However I want to create an instance of this control in a code-behind.

For example:

   NumericTextBoxControl txtNum = new NumericTextBoxControl();

But when I tried to reference the embedded TextBox via the exposed Get Property, the property is returning Null.

If using the control in an html page (.aspx), it works and from the code-behind, I can access the Get Property to get to the embedded TextBox.

How can I do a "new" in code-behind and have the Get Property not return Null???

Do you have any advice? Or solution?

Thanks

Sheir

Wednesday, February 14, 2007 3:12 PM by sheirali

# re: Turning an ascx user control into a redistributable custom control

Hi Sheir,

Instead of directly instantiating your control, try calling page.LoadControl(typeof(YourControlType), null).  This should do the proper initialization that will make it work.

David

Wednesday, February 14, 2007 3:38 PM by David Ebbo

# re: Turning an ascx user control into a redistributable custom control

David -- Please help. I have been using this technique and it works just fine as long as the User Control is a 1-file control, with inline code. As soon as I try to use a 2-file control (with both code-infront and code-behind) it does not work-- the UI cannot be seen at all when the resulting server control is used on an ASPX page. I have tried stating both classname="MyNamespace.MyClassName" and inherits="MyNamespace.MyClassName" in the <@control directive (as you mentioned in a post above) but when I do that I get a compile-time-error of "Missing partial modifier on declaration of type 'MyNamespace.MyClassName'; another partial declaration of this type exists". Can you give any more advice concerning how to make this work with the code-behind coding method in the User Control?

Thursday, February 15, 2007 2:22 PM by Mark Kamoski

# re: Turning an ascx user control into a redistributable custom control

Hi Mark,

You need to use a different class name for the inherits (which is the base class), and the classname attribute (which becomes a derived class).  Then make sure you always use the 'classname' class when you use it (just like in the inline mode).

David

Thursday, February 15, 2007 2:34 PM by davidebb

# re: Turning an ascx user control into a redistributable custom control

David -- I appreciate the extra assistance regarding using the classname and inherits attributes of the @Control directive. Your advice works like a charm. BTW, I have been using this method to create stand alone Server Controls. After than, I create a wrapper around those Server Controls to make them into WebPart Controls for use in SharePoint 2007 and plain old ASP.NET sites. The whole process is now VERY simple and fast thanks to your great tip here. Thank you very much. -- Mark Kamoski

Friday, February 16, 2007 12:20 PM by Mark Kamoski

# re: Turning an ascx user control into a redistributable custom control

Anybody having problems with Namespace?

Friday, February 16, 2007 7:01 PM by Jon A

# re: Turning an ascx user control into a redistributable custom control

David -- Thanks for your post, the inheritance issues is blindingly obvious once you realise it. Great catch.

Sunday, February 18, 2007 3:25 PM by Jonathan Langley

# re: Turning an ascx user control into a redistributable custom control

Has anyone been able to get these controls to be accessible from the toolbox? If we could do that this would be a 100% solution. Thanks much--

Saturday, February 24, 2007 5:10 PM by David Neely

# re: Turning an ascx user control into a redistributable custom control

One more issue. When I reference the dll as a private assembly, intellisense works fine. However, if I register the assembly in the GAC and reference it from there, the code still works fine however I get no intellisense and I get compiler warnings for the control name (i.e. the red squiggly with a message saying that this is not a known element). Any thoughts?

Saturday, February 24, 2007 11:25 PM by David Neely

# re: Turning an ascx user control into a redistributable custom control

I would like to use a custom control built with this method in another user control. No problem adding my custom control to a page. No problem adding my custom control to a new user control BUT when I add that new user control to a page I get "error rendering control - object not set to an instance of an object". Anyone seen this? Any ideers how to resolve?

tia

Darryl

Monday, February 26, 2007 10:37 AM by Darryl

# re: Turning an ascx user control into a redistributable custom control

Hi Darryl,

Is this an error that you see at design time in VS, or at runtime in the browser?  I would think that it should work fine at runtime, though there may be design time issues (some previous comments refer to this).

David

Monday, February 26, 2007 4:02 PM by davidebb

# re: Turning an ascx user control into a redistributable custom control

Hi Darryl,

I too got the error 'Object reference not set to an object". I used 2 separate files for code and design. But when I remove the code inside Page_Load event of user control, it worked fine. If I put any code to access any control inside user control, I got the above error.

Later I fixed the problem. As it was discussed by David, I need to specify a different name for our user control. But I do not have clear knowledge. David, Can you please explain us a bit on this? Thanks for an interesting and useful article.

Tuesday, February 27, 2007 5:07 AM by Anand

# re: Turning an ascx user control into a redistributable custom control

Can someone post a complete working sample USING CODE_BEHIND (source, VS solutions, test app, EVERYTHING!)? I'm trying various combinations (starting with instructions in the orginal post) and I am still getting NULL references exceptions for the child controls of the UserControl (.ascx) when I reference them in the Page_Load event of the UserControl. I'm missing something. Could the language have anything to do with it? I'm using VB iso C#.

HELP!

Tuesday, March 06, 2007 3:31 PM by DarylR

# re: Turning an ascx user control into a redistributable custom control

Hi david,

Is there a way to put the usercontrol into the toolbox and make it developer world easy ??

pls do let me know.

and has anyone tried it refrencing it to toolbox????

Tuesday, April 10, 2007 9:32 PM by GaneshThennavan

# re: Turning an ascx user control into a redistributable custom control

I think user option 1 + Web Deployment project is the best way

Monday, May 28, 2007 6:37 PM by Song Yuan

# re: Turning an ascx user control into a redistributable custom control

Is there any way to convert the usercontrol in a Web Application project into redistributable custom control

Saturday, June 02, 2007 9:24 PM by NAIDU

# re: Turning an ascx user control into a redistributable custom control

Yes, it should work essentially the same way in a Web Application Project.  The only difference is that the app's DLL (the one VS puts in 'bin') will need to be included as well.

Monday, June 04, 2007 12:43 AM by davidebb

# Turning off render of a user control in design of the parent page

Does anybody know how to turn of the render of a user control in the parent page. It is a pain when using lots of user controls and you are unsure what is on what page.  So in other words to make it like it was in VS 2003 with a little grey box.

Wednesday, June 13, 2007 8:19 AM by Mike Jones

# How to Register User Controls and Custom Controls in Web.config

Tip/Trick:HowtoRegisterUserControlsandCustomControlsinWeb.config I'vebeen

Tuesday, July 31, 2007 10:35 PM by WebServices

# re: Turning an ascx user control into a redistributable custom control

Hi david,

After converting the user control to custom control,is there any way to include this into toolbox?

Any help will be appreciated.

Monday, August 27, 2007 2:01 PM by Panchams

# re: Turning an ascx user control into a redistributable custom control

Is there any body who can help me in below.

After converting the user control to custom control,is there any way to include this into toolbox and drag and drop on any asp.net page?

Any help will be appreciated.

Wednesday, August 29, 2007 2:52 PM by Panchams

# re: Turning an ascx user control into a redistributable custom control

Can anyone helpme,

I tried this procedure for creating custom control.But while complation,i am getting the follwing error:

Could not load file or assembly 'App_Web_webusercontrol.ascx.cdcab7d2.dll' or one of its dependencies. The system cannot find the file specified.

Thanks and Regards

Preethi

Monday, September 03, 2007 7:51 AM by Preethi

# MCPD 70-547: Creando y seleccionando Controles

Damos inicio a la serie de post, basados en los temas de preparación para el examen 70-547 . Si eres

Thursday, November 15, 2007 2:10 AM by SergioTarrillo's RichWeblog

# DotNetNuke modules with Vis. Web Devel. 2008 Express | keyongtech

# Tagz | &quot;David Ebbo&#39;s ASP.NET blog : Turning an ascx user control into a redistributable custom control&quot; | Comments

# Misfit Geek Podcast

Click to Play Download the Current Episode MP3 WMA WMA (LoRes) ACC Episode #1 - Scott Hunter on the future of ASP.NET Development with Web Forms Scott Hunter is a Senior Program Manager Lead on the ASP.NET Team and, along with his team drives much of

Thursday, May 28, 2009 8:41 AM by Misfit Geek

# Episode #1 - Scott Hunter on the Future of Web Forms

Click to Play Download the Current Episode MP3 WMA WMA (LoRes) ACC Episode #1 - Scott Hunter on the future of ASP.NET Development with Web Forms Scott Hunter is a Senior Program Manager Lead on the ASP.NET Team and, along with his team drives much of

Thursday, May 28, 2009 8:51 AM by Misfit Geek

# David Ebbo s blog Turning an ascx user control into a redistributable | Paid Surveys

# David Ebbo s blog Turning an ascx user control into a redistributable | Cellulite Creams

# David Ebbo s blog Turning an ascx user control into a redistributable | debt solutions

New Comments to this post are disabled
 
Page view tracker