Click here to Skip to main content
Click here to Skip to main content

ASCX Control Parser

By , 23 Apr 2002
 

Introduction

Have you ever wanted to turn a .ASCX file into a distributable control? This program generates the source code for an .ASCX file so that you can compile it without having to distribute the .ASCX file. It comes close to simulating how the Page.LoadControl ("asdf.ascx") works.

Usage:

  • Run the exe file, paste in the ascx code into the textbox.
  • Choose the output class name (it will be created in the ASP namespace - but you can change this manually)
  • The "Has base class?" checkbox sets the parser to declare the controls or not. If this is ticked then the base class should have declared each control already.
  • Click go, and the C# code will be outputted in the same textbox.
  • Put the code into a new class in a web application and hopefully it should compile.
  • To add the code to a page you would do this (Assuming that the class was called CDefault and the namespace was left as ASP):
    //=======================================================
    private void Page_Load(object sender, System.EventArgs e)
    {
     // Put user code to initialize the page here
     Control c = new ASP.CDefault();
     this.Controls.Add ( C );
    }
    //=======================================================
    

Known issues: 

  • Compiler directives are ignored so registering controls other than asp controls (asp: namespace) must be done manually. You may have to do some editing on the output to suit your needs (such as code-behind class, etc).

  • List properties are not loaded properly. For example, the property Font-Names on a label control is actually a string list (string[]). The parser can't tell if a property is a list because it can't always do reflection on the type (any ideas how to fix this?).

TODO:

  • Add a VB.NET output, currently the output is only written for C#.
  • Make it a Visual Studio Add-In.
  • Recognise compiler directives.

Registration

If you like it, please send an email to bvk@villagechief.com

If you make any changes or additions, please send them to me at the above email address.

Copyright and License

This is freeware to do with as you see fit. The author accepts no responsibility for any damage or data loss caused by this program.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Ben van Klinken
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralhmmmmemberLawrence Botley13 Nov '06 - 10:03 
After some inspection of your app I come to the point that its pretty pointless...
 
You claim your application can compile ASCX files but this is not really the case for the following reasons:
 
You can only compile HTML and cannot use server controls of any sort
You cannot utilise code behind
 
Your application is simple a wrapper for HTML.
 
why not just tell users to get the HTML they wish to render and tell to do the following:
 
protected override void CreateChildControls()
{
this.Controls.Add(new LiteralControl("INSERT PLAIN HTML HERE"));
}
 
Thats basically your application? yes?
 
Its very misleading indeed!
 
So does anyone know if you can compile ASCX files for real?
 
Within the twentieth century, an ultraintelligent machine will be built and that it will be the last invention that man need make.
 
I.J. Good

GeneralRe: hmmmmemberkelasings15 Sep '07 - 15:30 
Hi Lawrence,
 
It is very easy to compile an ascx and distribute it.
 
All you have to do is create the ascx control, build it and then go the bin folder where the compiled file is located. Then you can use the location to add a reference to the .dll in your website project.
 
kelasingsSmile | :)
QuestionRe: hmmmmemberstixoffire5 May '08 - 6:59 
I am interested in this component - but Lawrnece made some points I am interested about ..
 
He claims the code only compiles html - in other words if your user control has tags such as <asp:datagrid id="dg1"> this component will nto compile.. is this the case with your cotrol - does it operate as he is stating ??
GeneralRe: hmmmmemberstixoffire5 May '08 - 7:29 
I ran the executable as a test and it is as lawrence stated. You are simply transforming the object , the html of the code into literal controls, his method transforms it all at once into one control (simpler).
 
But neither of those methods really provides for the complete functionality you would want from a custom control - with design time elements and the ability to wire up events.
At least from what I am looking at.
I cannot set properties in the design time etc.. so is it really redistributable .. ?? reuseable yes. What about the code behind ??
GeneralQuick Update with VBmemberTodd77777722 Feb '06 - 15:51 
I made some updates to this project if anyone's interested. I quick pass at VB support and a bit of UI work. No 2.0 testing yet though. Maybe... Someday... Smile | :)
http://longlostcousins.com/blogs/todd/archive/2006/02/02/ParsingUserControlsintoServerControls.aspx

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 24 Apr 2002
Article Copyright 2002 by Ben van Klinken
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid