Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get an .ascx file to compile in a class library?

Tags:

c#

.net

asp.net

I know this isn't possible; I'm looking for a workaround really. I have a bunch of classes in a .dll file that all inherit the same abstract HtmlGenerator class. All these do is generate content HTML for parts of the page, based on certain user settings. I also have JavascriptGenerator and CssGenerator, which do pretty much the same thing. Much like a UserControl ;)

All these controls are either rendered on the page or can be loaded via AJAX calls.

The problem I'm having is that the strings contain a lot of " and it's getting a bit ugly to put in strings. It'd be nice if I could get them into .ascx files.

I understand that ascx files can't be placed in a class library because the references to other files, such as images, aren't going to work. But all my files are generated HTML based on certain profile data. There aren't any images and there isn't any actions taking place, such as editing values in a database.

You can inherit UserControl and override the Render method in a class library, but is there a way of getting an ascx file to be compiled in a class library? Or is there a decent enough workaround? Perhaps I should put the HTML in the resources file?

like image 467
Connell Avatar asked Dec 21 '25 07:12

Connell


1 Answers

Give this a shot:

  1. Close VS.NET 2005.
  2. Open the directory C:\Program Files\Microsoft Visual Studio 8\Web\WebNewFileItems\CSharp (assuming a default installation of VS.NET).
  3. Open the CSharpItems.vsdir file in Notepad. Select the text and copy it to the clipboard.
  4. Now open up the file C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjectItems\CSharpItems.vsdir and paste the contents of the clipboard underneath the existing text.
  5. Now copy the contents of C:\Program Files\Microsoft Visual Studio 8\Web\WebNewFileItems\CSharp (excluding CSharpItems.vsdir) into the folder C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjectItems.

Here's a post from Scott Guthrie that might help too:
http://webproject.scottgu.com/CSharp/UserControls/UserControls.aspx

like image 164
James Johnson Avatar answered Dec 22 '25 21:12

James Johnson