Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Complex properties (Button) not persisting in webcontrol

Reply
Thread Tools

Complex properties (Button) not persisting in webcontrol

 
 
Phillyboy123
Guest
Posts: n/a
 
      11-19-2003
This seems to be a common issue and one that I have not found a
solution to. What I want to do is theoreticly simple. I have tried
creating webcontrols with simple properties string e.t.c and all work
fine. I am now in the process if trying to create a webcontrol that
contains more complex properties. In this case a Property of type
Button. I've played around with all of the recomended metadata
ParseChildren(true/false), PersistChildren(true/false),
PersistanceMode e.t.c. I've also been using "Developing Microsoft
ASP.NET server controls and components" by Nikhil Kothari and Vandana
Datye" but with no success in this area.

At designtime the control is rendered on the page correctly and the
Properties of the Button within the custom control appear in the
properties toolbar/palette. Changes to the Buttons properties ie. Text
or BackColor seem to take effect when the page is redrawn however
these properties do not persist.

1. There values are lost when the project is rebuilt or ran.
2. The HTML for the aspx page has not changed to reflect the new
property values.

Below is the code for the class.

using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI.Design;

namespace DynamicWebControls.Controls
{
public class TestControl:
System.Web.UI.WebControls.WebControl,INamingContai ner
{
Button _myButton;

protected override void CreateChildControls()
{
Controls.Clear();
Controls.Add(MyButton);
}

[
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty)
]
public Button MyButton
{
get
{
EnsureChildControls();
if(_myButton==null)_myButton=new Button();

return _myButton;
}
set
{
_myButton = value;
}
}

protected override void Render(HtmlTextWriter writer)
{
MyButton.RenderControl(writer);
}
}
}

Thanks in advance for your help.

Phil.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Persisting collection data of a webcontrol when leaving the collection editor in VS2005 mehdi.mousavi@gmail.com ASP .Net Building Controls 1 05-19-2006 03:49 PM
extender provider properties not persisting ! JezB ASP .Net 1 06-22-2004 10:04 AM
Properties not persisting at design time. Steve Barker ASP .Net Building Controls 0 01-22-2004 04:56 PM
Complex properties (Button) not persisting in webcontrol Phillyboy123 ASP .Net Building Controls 1 01-15-2004 07:55 PM
Persisting properties in templates and not the control itself Alessandro Zifiglio ASP .Net Building Controls 0 11-09-2003 11:31 AM



Advertisments