When base class is used for UserControl, VS designer fails to load ASCX file

J

Jiri Zidek

The problem is that I cannot use VS graphical designer to design my ASCX
controls that do not inherit directly from System.Web.UI.UserControl but
they inherit from my base class (which is in fact derived from
System.Web.UI.UserControl).

The VS gives me error:
"The file could not be loaded into the Web FOrms designer. Please correct
the foloowing error and then try loading it again:
The designer could not e shown for this file because none of the classes
within it can be designed. The designer inspected the following classes in
the file:
WebUserControl1 -- The ase class 'WebApplication1.BaseWebUSerControl' could
not be loaded. Ensure the assembly has been referenced or built if it is
part of the project. Make sure all of the classes used in the page are built
or referenced in the project."

Important point: compiling project is OK and when running the pages with
such controls everything wokrs fine.

What should I make to work it with designer again ? Some attributes ? Some
interfaces reimplement ?

Thanks - Jiri

Detailed description:

The idea is similar to idea of baseclass for pages described in
http://www.codeproject.com/aspnet/AspNetInheritance.asp. I need to use some
common functionality for set of web UserControls, I decided to use a common
baseclass that inherits form System.Web.UI.UserControl:

public abstract class BaseWebUserControl : System.Web.UI.UserControl {
......
}

The ASCX file of this base class is almost empty:

<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="BaseWebUserControl.ascx.cs"
Inherits="WebApplication1.BaseWebUserControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>

Then I construct my derived ASCX control with code behind:
public class WebUserControl1 : BaseWebUserControl {
......
}

The ASCX file of this derived control is simple:

<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="WebUserControl1.ascx.cs"
Inherits="WebApplication1.WebUserControl1"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:textbox id="TextBox1" runat="server"></asp:textbox>
<asp:button id="Button1" runat="server" text="Button"></asp:button>

The concept works well for runtime, bud VS designer gets confused.
I use VS2003. No problem to send simple project showingthe effect.
 
J

Jiri Zidek

Thanks for response. Your clases are almost the same as in my testing
project. To be sure I have made a test with yours: a) New WebApplication, a)
copied your files to the aspx/cs directory, c) Include in project. d) Double
click on DerivedUserControl.ascx in Solution explorer yields the same error
as described below.
See Err-1.png on path http://firma.atlantis.cz/msft . When pressing OK, the
ASCX file is displayed but only in HTML view, no Design view available - see
Err-2.png.
But again: Bulding - OK, running testpage,.aspx - OK. see OK-3.png in the
URL above.

Try with your project to do the same (double click DerivedUserControl.ascx,
which normally opens design view of ascx) - if working for you - then the
defect is in my VS2003 installation so I will consider reinstallation (and
please rceive appologise my bothering).

If anything more needed no problem.

Regards
Jiri
 
S

Steven Cheng[MSFT]

Hi Jiri,

Thanks for your response. Yes, I just test follow the exact same steps you
mentioned, double click the
"ascx " file to display the Usercontrol in VS.NET's design view and that
works ok. Also, I just test again on a XP SP2 box (my original test on a
win2k3 box), both with .net framework1.1 vs.net2003 installed. Not sure
any
enviromential specific problems on your box. But I think before you
considering reinstall, it is recommend that you try testing on some other
machines on your side to double check this.

If there is anything else we can help, please feel free to post here.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
J

Jiri Zidek

Hello,

Good idea. I have tested this "inheritance" on another machine and designer
works without the problem. So I conclude - the defect is in my own VS
installation. Sorry for bothering.

Jiri
 
S

Steven Cheng[MSFT]

Thanks for your followup Jiri,

You're always welcome to post here.
Good luck!

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top