473,223 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,223 software developers and data experts.

Server Control Collection Properties Solutions,Problems MVP Advice Requested

microsoft.public.dotnet.framework.aspnet.buildingc ontrols

I have solved most of my Server Control Collection property issues.
I wrote an HTML page that describes all of the problems that I have
encountered to date and the solutions (if any) that I found.
This page also has all of the source code in a compressed file that you are
free to download and I have included links where I found solutions to most
of my problems.

I will paste the contents of the web page here. However, I did not want to
include the 57K zip of the source code in a News Group post.
After all of these problems I am wondering if I should even be writing
server controls using collection properties in this manner?
Do any of the Microsoft MVP's out there have any advice regarding this

For the record this is what is included in the source code:

Two classes that have collection properties
These classes each have a Designer,ControlBuilder, and CollectionEditor for
the collection property
The ImageUrl property of the BaseButton control has a custom UITypeEditor.
The collection properties uses a custom type for the collection that will
allow the custom UITypeEditor to work and will stop the Ambiguous match
found error.

The ScheduleNavigation and ScheduleGlobal controls should fully work as
expected in design time.
The project is a C# Web Application so you will need to create a virtual
directory named TestServerControls

Server Control Collection Properties Issues and Advice

The purpose of this document is three fold. First, I want to document what
I've learned in the hopes that others will help me find solutions to the
problems that still remain. Second, I would like to prevent developers from
having to spend three weeks to get collection properties to work. Third, I
hope that this documentation will lead someone at Microsoft to document what
we SHOULD be doing in this area.

Source code is included here TestServerControls.zip


This was my first attempt at developing an ASP .NET web server control. I
have worked in C-Sharp on various projects for the past two years and after
spending two days reading up on the subject, I felt confident that I could
design a server control for use by the other developers in my company.

The Plan:

I wanted to develop a group of composite server controls that would give
other developers the ability to construct selected portions of a web page.
A developer would drop these controls on the design surface and use the
property grid to add and remove other pre-developed server controls. These
controls would automatically add any necessary supporting logic and keep the
look and feel consistent. With my background using C-Sharp in Windows
Forms, I felt I could get a prototype working within two days. That was
three weeks ago.

In short, I wanted the behavior of the Table Row Collection Editor (Drop a
table on the design surface and edit the Rows property) except I wanted the
developer to be able to choose from a variety of controls to add.

The Problems:

Problem 1:

My first problem still exists but only on my PC at work. It involves my
Visual Studio IDE. I could NOT get my collection editor to allow the
developer to select multiple items. In fact the collection editor was not
working at all. I found that this problem ONLY exists on my PC at work at
not on any of the other 5 PC's that I tested against. My best guess for
this problem comes from the following MSDN Library information on the
CollectionEditor.CreateInstance method

..NET Framework Security:

a.. Full trust for the immediate caller. This member cannot be used by
partially trusted code. For more information, see Using Libraries From
Partially Trusted Code
I'm guessing that I have some security issues with my PC that is preventing
the collection editor from working correctly. To get around this problem, I
am now coding under Virtual PC until I can either resolve the issue or get
the time to rebuild my PC. (What JOY)

Problem 2:

I am getting the following error message when I try and use my collection

Ambiguous match found

Knowledge base article KB823194 provides the solution.

Problem 3:

The collection property appears to be working. However the control whose
properties I am attempting to edit will not allow me to edit the ImageUrl
property. My control inherits from System.Web.UI.WebControls.Image and it
is critical that I'm able to edit this property.

Partial Solution Part 1.

Articles at http://www.artima.com/forums/flat.js...2&thread=38250 and
http://www.devx.com/DevX/Article/20920/0/page/1 followed by looking at the
ImageUrlEditor in reflector leads me to the following conclusion.

The editor is unable to get a service provider when my control is hosted
within my collection property. This is a major problem because other
controls will have a similar problem. The partial solution is to create a
UITypeEditor as indicated in the first article and to override the
UITypeEditor for the ImageUrl property in my derived class. This will work
only as long as the new UITypeEditor can obtain the Parent property in my
derived class. This leads us directly into Partial Solution Part 2.

Partial Solution Part 2.

The only way for my derived control's Parent property to be set is for it to
be in the Controls collection of my server control. Let me state this
differently. The only way for the modified UITypeEditor to work is if my
collection property also adds/removes items into the Controls collection of
the server control. So that is what my collection property now does. I was
hoping that the custom UITypeEditor would not be needed after I modified the
collection property but I was wrong.

Problem 4:

The HTML output from my collection property is malformed. There is no begin
tag just the inner content and an end tag. Experiments with various
attributes leads to the following settings that fix the problem.

On the server control class I have the following attributes set:



On the property collection I have the following attributes set:





Problem 5:

I created a designer for my class but it was not working. This was a logic
problem based on assumptions that I had made by reading various books and
articles. I assumed that I was developing a composite control and that I
should have the designer force the server control to create its children.
That way I could let the base GetDesignTimeHtml method render the control
correctly. But to my surprise (I HAD NOT CREATED A COMPOSITE CONTROL). I
thought I had a composite control because:

1.. I was overriding the Controls property.
2.. I was creating all of my objects in CreateChildControls and adding
them to my Controls collection.
3.. I was letting the default rendering logic render the HTML.
But I had forgotten about problem #3.

Problem 3 forced me to use the Controls collection to hold every object that
was added into my collection property. Using the designer/rendering logic
in this fashion changes the state of the Controls collection, which changes
the state of the Parent property in all of the controls in the Controls
collection. In short, my designer needed to render the state of the server
control WITHOUT modifying the contents of the Controls collection.

In my humble opinion, a composite control meets the criteria stated in items
1,2, and 3 but it also has an important fourth criteria. It does not
negatively effect the state of its properties during rendering. Meeting
this criteria allows you to use the default rendering logic within the
designer and at run-time without side effects.

Questions and problems remaining to be solved:

1.. Problem 1 of course.
2.. When System.Web.UI.WebControl objects are created and added into the
collection property they do not have the same properties set as if they were
dropped on the design surface. I would like the ID property defaulted for
every control that gets added. However, in order to do this I have to
inherit from the control and override either the DefaultProperty
attribute,the ShouldSerialize, or the Reset methods. This works but is a
royal pain.
3.. Is there a better method of getting collection properties to work and
if so will the controls within the property still work correctly within the
property grid?(Problem 3)
4.. Am I attempting to use collection properties in a manner that is
outside the design paradigm?

Nov 18 '05 #1
2 3136

great work. just want to add that if you want your collection persist as
sub control tags you should set PersistenceMode to InnerDefaultProperty.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2
My collection is correctly persisting its contents as sub control tags.
Its just that the HTML generated within the sub control tags is not the same
as what is generated if the control was dropped on the design surface.
And if memory serves me correctly, the HTML that is persisted is the same
regardless of the PersistenceMode attribute setting.

I also can't use the InnerDefaultProperty on the ScheduleGlobal class
because it has two collection properties.

I'm going out on a limb here for this next statement.
I think that to get the contents of the collection properties to persist
within the ASPX page correctly I am going to have to write a custom
DesignerSerializer. Is this guess correct or will implementing a custom
DesignSerializer only allow me to control the serialization of the code in
the code behind page?


However, I don't
"Natty Gur" <na***@dao2com.com> wrote in message

great work. just want to add that if you want your collection persist as
sub control tags you should set PersistenceMode to InnerDefaultProperty.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
by: Martin Robins | last post by:
I have never dabbled with ASP.NET until now so be warned! I have created a web application with the single default form: WebForm1.aspx and when I try to display it I get this error. My...
by: Ken Varn | last post by:
I am just starting the process of creating ASP.NET server controls. I have created controls for .NET applications, but have just started with ASP.NET. I am a little confused about some areas that...
by: dx | last post by:
I have the Microsoft Press: Developing Microsoft ASP.NET Server Controls and Components book. It's starting to shine some light on control development but there is something about composite...
by: Shimon Sim | last post by:
I have a custom composite control I have following property
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
by: Jordan S. | last post by:
Using .NET 3.5... I have the following class: class NodeDescriptor { // Properties only in this class public int NodeID { get; private set; } public int ParentNodeID { get; private set; }...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.