473,387 Members | 1,721 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,387 software developers and data experts.

Updating Design Time When Property Changes

I've written a composite custom control which I would like to have update its design-time display when one of several properties
changes at design time. These custom properties are not simply the exposed properties of the constituent controls (e.g., they
control how many constitutent controls are displayed).

I am at a loss as to how to go about doing this. I have a custom designer for the control, but I don't see any functionality in the
base class (ControlDesigner) to "monitor" property changes and then alert the DesignerHost that the control needs to be redrawn.

I am also confused as to why I've just spent 2 hours trying to find references to solving this problem on google, with no
joy...since it seems like it would be a very common problem :). But that's another story.

Any leads or references would be appreciated!

- Mark
Jan 31 '07 #1
4 2684
Hi Mark,

I'm not very clear about your question. For a simple property that needs to
assign to the constituent control, if you do that in CreateChildControls,
you will notice you don't need to do anything to update the designer since
the CreateChildControls will be called again to update the designer when
the property is changed. Here's a test:

1) Suppose we have following simple CompositeControl:
public class Class1 : CompositeControl
{
private Label m_lblName;

public string NameLabel
{
get {
Debug.WriteLine("NameLabel Getter");
return ViewState["NameLabel"] as string;
}
set {
Debug.WriteLine("NameLabel Setter");
ViewState["NameLabel"] = value;
}
}

protected override void CreateChildControls()
{
Debug.WriteLine("CreateChildControls");

Controls.Clear();

m_lblName = new Label();
m_lblName.ID = "lblName";
m_lblName.Text = NameLabel;
Controls.Add(m_lblName);
}
}

2) Use this control in a WebForm and change its NameLabel property, make
sure you have turned on Debug in compilation options; and use DebugView
from sysinternals to view the output. You will notice every time you change
the NameLabel property, the CreateChildControls will get called again.

I understand in your specific case, you're using your own designer, the
behavior will be controlled by the designer. Would you please tell me more
about your custom designer and what's your objective to achieve when using
it?

Based on my understanding, when a property is changed, OnComponentChanged
will be called and you will know a property is changed. On the other hand,
if you changed a property in code and want to update the designer surface,
you need to call this method.
#ControlDesigner.OnComponentChanged Method (System.Web.UI.Design)
http://msdn2.microsoft.com/en-us/lib...controldesigne
r.oncomponentchanged.aspx
If in doubt, please send me a simple but complete project to demonstrate
the issue.
Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 31 '07 #2
Okay, it turns out it's so simple I missed it: clear the Controls collection, set ChildControlsCreated to false and call
EnsureChildControls(). Although, for some reason, if you clear the Controls collection while ChildControlsCreated is false,
CreateChildControls() gets called automatically on the Clear()...which means it gets called twice. So you have to test the state of
ChildControlsCreated first.

- Mark

On Tue, 30 Jan 2007 17:57:10 -0800, Mark Olbert <Ch*********@newsgroups.nospamwrote:
>I've written a composite custom control which I would like to have update its design-time display when one of several properties
changes at design time. These custom properties are not simply the exposed properties of the constituent controls (e.g., they
control how many constitutent controls are displayed).

I am at a loss as to how to go about doing this. I have a custom designer for the control, but I don't see any functionality in the
base class (ControlDesigner) to "monitor" property changes and then alert the DesignerHost that the control needs to be redrawn.

I am also confused as to why I've just spent 2 hours trying to find references to solving this problem on google, with no
joy...since it seems like it would be a very common problem :). But that's another story.

Any leads or references would be appreciated!

- Mark
Jan 31 '07 #3
Walter,

Thanx for the quick reply. Since my reply to myself about the solution was pretty incoherent, let me try and explain the problem and
the solution differently.

The state property in question involves the number of child controls to include in the composite control. It's not, therefore, a
property of a child control which could simply be exposed publicly -- changing the property value "radically" changes the makeup of
the composite control.

When a property like the Font of a composite control changes, and you assign the property to the child controls, I guess the change
is propagated through the controls and forces a redraw of the design-time display.

In my case I had to force a recreation of the control hierarchy when the property in question changed. I did that by inserting the
following code block in the property set method:

if( ChildControlsCreated )
{
Controls.Clear();
ChildControlsCreated = false;
EnsureChildControls();
}

I added the test for ChildControlsCreated when I noticed that, without it, the initial setting of the property (i.e., during the
composite control's initialization, when no child controls had been created) caused CreateChildControls() to be called both when I
called Controls.Clear() and when I called EnsureChildControls (because I'd reset ChildControlsCreated after the Clear). I didn't
want to create the control hierarchy twice, hence the inclusion of the test.

- Mark
Jan 31 '07 #4
Mark,

Thanks for sharing your solution here. You're right that if a property will
affect the control hierarchy, the property ChildControlsCreated will need
to set to false to force it recreate the control hierarchy again.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 31 '07 #5

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

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
4
by: Dave | last post by:
Hello. I am trying to update attributes in LDAP/Active directory from my application that is written in VB.NET. I am using Directory Services to do so. I do not get any errors during the...
5
by: Guy | last post by:
Guys Hope someone can help me! I'm having real problems getting properties I type against a control I have written at design time I have written a control by inheriting from the Button control....
0
by: Ziyad Makki | last post by:
Hello, I have created a Web Composite Control. I have also created a designer class that is used to render the control at design time. All though it dose work, I have been experiencing some...
3
by: sling blade | last post by:
Hi, I am woring in VS.Net 2003. I am trying to make minor adjustments to my webpage via my stylesheet. However the changes that I make don't take effect until I close VS.Net and open it back...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
34
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have...
0
by: tomislav.bartolin | last post by:
Hi, I have a EditWindow class which inherits the System.Windows.Form class and has a public property named EntityType. I have created a custom UITypeEditor for this property and this works fine....
33
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.