asp.net custom server control not showing when dragged onto web fo

S

SpencerW

I've created a custom composite calendar server control in asp.net. I've
compiled the dll and added it to my toolbox, but when I drag and drop it onto
a web form, I don't see the control in the designer. All I can see is a tiny
little green arrow. It shows up in the property explorer for the page and
the control works just fine when the page is rendered on a browser. The
problem is that I don't see it on the form in the vs.net web form designer
and that is perplexing. Anyone have any ideas on why this is happening and
what I can do to fix it?
 
S

Steven Cheng[MSFT]

Hi Spencer,

Welcome to ASPNET newsgroup.
From your description, you're developing a custom webserver control
(composite control) which will contain a Calendar inside it. However when
you draged the control on a webform page at design-time you found it
displayed nothing on the webform's design-view, yes?

Based on my understanding, what you have encountered was the expected
behavior. This is because by default, VS.NET will call the Control's Render
method get the html displayed in design-view. And for Composite control, we
used CreateChildControls to construct the control hierarchy rather than
using Render method , so you'll get the empty(an arrow only) in
design-view.

If we do need to provide our customized Html View for our control at
design-view, we can consider creating a custom control designer for our
composite control. For example:

we can apply a custom ControlDesigner class for a custom control like:

[ Designer("CustomControls.Design.SimpleDesigner, CustomControls.Design")]
public class Simple : WebControl {
....................
}

And we can override the "GetDesignTimeHtml() " method of the
ControlDesigner class which is used to return the html code to display in
IDE at design-time. For detailed description, you can refer to the
following MSDN document:

#Implementing a Simple Web Forms Control Designer
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconhtmldesignersample
..asp?frame=true

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

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

SpencerW

Steve,
Thanks for the reply, you are correct in your diagnosis of the problem. The
code in the article you provided a link to seems as though it should work.
One problem with it though - I cannot import System.Web.UI.Design or inherit
from System.Web.UI.Design.ControlDesigner. Also, I'm not sure what the
CustomControls library is that is imported in the example, but I cannot
import that either. Am I missing a reference or a file or something? Please
let me know the answer to this question and it should answer my initial one.
Thanks.

Spencer
 
S

Steven Cheng[MSFT]

Hi Spencer,

The "CustomControls.Design" in the example is just a test namespace, we
don't need to care about it. And the ControlDesigner class is under the
System.Web.UI.Design namespace. However, the System.Web.UI.Design
namespace are not in the same assembly with the System.Web.UI namespace.
We need to add reference of the

System.Design.dll (contains the System.Web.UI.Design namespace) first.

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.)
 
S

SpencerW

Yup, that did it. Too bad the ms article didn't mention that. Thanks for
the help.

SpencerW said:
Steve,
Thanks for the reply, you are correct in your diagnosis of the problem. The
code in the article you provided a link to seems as though it should work.
One problem with it though - I cannot import System.Web.UI.Design or inherit
from System.Web.UI.Design.ControlDesigner. Also, I'm not sure what the
CustomControls library is that is imported in the example, but I cannot
import that either. Am I missing a reference or a file or something? Please
let me know the answer to this question and it should answer my initial one.
Thanks.

Spencer


Steven Cheng said:
Hi Spencer,

Welcome to ASPNET newsgroup.
From your description, you're developing a custom webserver control
(composite control) which will contain a Calendar inside it. However when
you draged the control on a webform page at design-time you found it
displayed nothing on the webform's design-view, yes?

Based on my understanding, what you have encountered was the expected
behavior. This is because by default, VS.NET will call the Control's Render
method get the html displayed in design-view. And for Composite control, we
used CreateChildControls to construct the control hierarchy rather than
using Render method , so you'll get the empty(an arrow only) in
design-view.

If we do need to provide our customized Html View for our control at
design-view, we can consider creating a custom control designer for our
composite control. For example:

we can apply a custom ControlDesigner class for a custom control like:

[ Designer("CustomControls.Design.SimpleDesigner, CustomControls.Design")]
public class Simple : WebControl {
....................
}

And we can override the "GetDesignTimeHtml() " method of the
ControlDesigner class which is used to return the html code to display in
IDE at design-time. For detailed description, you can refer to the
following MSDN document:

#Implementing a Simple Web Forms Control Designer
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconhtmldesignersample
.asp?frame=true

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

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

Steven Cheng[MSFT]

You're welcome Spencer,

Thanks again for using MSDN newsgroup.

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

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top