473,695 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Server Control Collection Properties Solutions,Probl ems MVP Advice Requested

NOTE ALSO POSTED IN
microsoft.publi c.dotnet.framew ork.aspnet.buil dingcontrols

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.
http://users.adelphia.net/~brianpcla...tionIssues.htm
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
matter?
Thanks

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

Two classes that have collection properties
These classes each have a Designer,Contro lBuilder, and CollectionEdito r 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 ScheduleNavigat ion 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 TestServerContr ols

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 TestServerContr ols.zip

Background:

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
CollectionEdito r.CreateInstanc e 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
property.

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.W ebControls.Imag e 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:

ParseChildren(t rue),

PersistChildren (false),

On the property collection I have the following attributes set:

PersistenceMode (PersistenceMod e.InnerProperty ),

DesignerSeriali zationVisibilit y(

DesignerSeriali zationVisibilit y.Visible),

NotifyParentPro perty(true),

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 GetDesignTimeHt ml 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 CreateChildCont rols 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.W ebControl 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 3172
Hi,

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

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 InnerDefaultPro perty 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
DesignerSeriali zer. Is this guess correct or will implementing a custom
DesignSerialize r only allow me to control the serialization of the code in
the code behind page?

Thanks
Brian

However, I don't
"Natty Gur" <na***@dao2com. com> wrote in message
news:O8******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

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

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

6
6771
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 the SQL Profile to watch the T-SQL-Command which Access ( who creates the commands?) creates and noticed:
5
310
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 understanding was that ASP.NET was supposed to set itself up, especially as I am using Windows Server 2003. Can anybody give me instruction as to resolution; what folder should I be granting the access to? The path shown only exists as far as the...
3
1861
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 I am hoping someone can help clear up. 1. What is the difference between initializing a control in the constructor, vs the OnInit(), vs the CreateChildControls() methods? 2. The control that I created contains an Items collection attribute...
10
2317
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 controls that I don't understand... I've included a snippet from Chapter 12 below on Composite Controls: <start> Override the CreateChildControls method to instantiate child controls, initialize them, and add them to the control tree. Do not perform...
7
2994
by: Shimon Sim | last post by:
I have a custom composite control I have following property
2
4919
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 being updated by some other process through remoting. When the page loads, I init the tree, and in my browser I can see the initialized tree. The problem is that every time that I receive update to tree from the remote process,
2
6955
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 attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
2
1135
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; } public string SomeStringValue { get; set; } // etc... (2 more int and 7 more string properties, that's all.) }
0
8619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8555
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9112
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8971
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8824
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8817
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4571
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2994
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.