473,401 Members | 2,139 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,401 software developers and data experts.

Own aspNet control - tag contents as default property

Hello,
I have writen a simple aspnet control MyCtrl and want to use it as follows:
(c01 may be the tag-prefix):
<c01:MyCtrl>this is a simple text</c01:MyCtrl>.

The control-code:

[DefaultProperty("Text02")]
[ToolboxData("<{0}:MyCtrl runat=server></{0}:MyCtrl>")]
[PersistChildren(true)]
[ParseChildren(false)]
.... MyCtrl .... inhereted from Control (not from WebControl)
..................
//the property which should be used for the innertext.
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
[PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
public string Text02
{
get
{
String s = (String)ViewState["Text02"];
return ((s == null) ? String.Empty : s);
}

set
{
ViewState["Text02"] = value;
}
}
...............

the web-page:

..................
<c01:MyCtrl ID="myId" runat="server">this is a simple text</c01:MyCtrl>
...........

Now if there is nothing between the tags means I have:
<c01:MyCtrl ID="myId" runat="server"></c01:MyCtrl>
and I go from html-view to design-view, no problem.
Now I can enter in the propertyView under the property Text02: this is a
simple text.

If I go now to the html-view I see:
<c01:MyCtrl ID="myCtrl" runat="server"></c01:MyCtrl>
means the text is not there
If I now write a text so I have
<c01:MyCtrl ID="myCtrl" runat="server">this is a simple text</c01:MyCtrl>
and if I now go back to the design View I do not see the text under the
property Text02

Seems the designer cannot write/read 'this is a simple text' within the
tags.

What is going wrong.
Any help would be nice.
Thank you.
Rolf Welskes

Sep 28 '06 #1
2 2387
Hello Rolf,

As for the custom webcontrol, based on the code you provided, I found there
are two things we may take care here:

1) If you want to persist Control's properties inside Control's tag(inner
property), you need to set the "ParseChildrenAttribute" as "true", this
indicate that the inner content of the control tag will be parsed as
control properties.

#ParseChildrenAttribute Class
http://msdn2.microsoft.com/en-us/lib...ildrenattribut
e.aspx
2) The "PersistChildrenAttributeA" is used together with the
"parseChildrenAttribute", from the MSDN document remark below:

===================
The PersistChildrenAttribute is used in combination with the
ParseChildrenAttribute to determine how nested content of a control is
interpreted. If PersistChildrenAttribute is true and ParseChildrenAttribute
is false, the nested content contained within an ASP.NET server control is
persisted as controls.If PersistChildrenAttribute is false and
ParseChildrenAttribute is true, the nested content is persisted as
properties of the server control.
=============

You can find that if you want to persist property into control's inner
content, you should set "PersistChildAttribute" to false and
"ParseChildrenAttribute" to true. e.g.

[ParseChildren(true,"Description")]
[PersistChildren(false)]
Here is a complete test control for your reference:

==================================
[DefaultProperty("Description")]
[ToolboxData("<{0}:PropertyControl
runat=server></{0}:PropertyControl>")]
[ParseChildren(true,"Description")]
public class PropertyControl : WebControl
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}

set
{
ViewState["Text"] = value;
}
}

[Bindable(true)]
[Category("Appearance")]
[DefaultValue("default description")]
[Localizable(true)]
[PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
public string Description
{
get
{
String s = (String)ViewState["Description"];
return ((s == null) ? String.Empty : s);
}

set
{
ViewState["Description"] = value;
}
}

protected override void RenderContents(HtmlTextWriter output)
{
output.Write("<br/><hr/>");
output.Write("<br/>Text: " + Text);
output.Write("<br/>Description: " + Description);
output.Write("<br/><hr/>");
}
}

=================================

Hope this helps.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

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.


Sep 29 '06 #2
Hello,
thank you for your help, it works.

Thank you again.
Rolf Welskes
"Steven Cheng[MSFT]" <st*****@online.microsoft.comschrieb im Newsbeitrag
news:44**************@TK2MSFTNGXA01.phx.gbl...
Hello Rolf,

As for the custom webcontrol, based on the code you provided, I found
there
are two things we may take care here:

1) If you want to persist Control's properties inside Control's tag(inner
property), you need to set the "ParseChildrenAttribute" as "true", this
indicate that the inner content of the control tag will be parsed as
control properties.

#ParseChildrenAttribute Class
http://msdn2.microsoft.com/en-us/lib...ildrenattribut
e.aspx
2) The "PersistChildrenAttributeA" is used together with the
"parseChildrenAttribute", from the MSDN document remark below:

===================
The PersistChildrenAttribute is used in combination with the
ParseChildrenAttribute to determine how nested content of a control is
interpreted. If PersistChildrenAttribute is true and
ParseChildrenAttribute
is false, the nested content contained within an ASP.NET server control is
persisted as controls.If PersistChildrenAttribute is false and
ParseChildrenAttribute is true, the nested content is persisted as
properties of the server control.
=============

You can find that if you want to persist property into control's inner
content, you should set "PersistChildAttribute" to false and
"ParseChildrenAttribute" to true. e.g.

[ParseChildren(true,"Description")]
[PersistChildren(false)]
Here is a complete test control for your reference:

==================================
[DefaultProperty("Description")]
[ToolboxData("<{0}:PropertyControl
runat=server></{0}:PropertyControl>")]
[ParseChildren(true,"Description")]
public class PropertyControl : WebControl
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}

set
{
ViewState["Text"] = value;
}
}

[Bindable(true)]
[Category("Appearance")]
[DefaultValue("default description")]
[Localizable(true)]
[PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
public string Description
{
get
{
String s = (String)ViewState["Description"];
return ((s == null) ? String.Empty : s);
}

set
{
ViewState["Description"] = value;
}
}

protected override void RenderContents(HtmlTextWriter output)
{
output.Write("<br/><hr/>");
output.Write("<br/>Text: " + Text);
output.Write("<br/>Description: " + Description);
output.Write("<br/><hr/>");
}
}

=================================

Hope this helps.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

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.


Oct 1 '06 #3

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

Similar topics

3
by: PAUL EDWARDS | last post by:
I have a windows form that is bound to a datatable. In VB6 I could just update the field contents and it would be updated in the database, however if I update the text property of the control from...
6
by: Bruce Rusk | last post by:
I'm using Stephen Lebans' RTF2 control in a report, and have discovered what may be a slight bug in it. I have a lot of non-Western language (Chinese) text in my RTF field, and such records get...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
0
by: adam | last post by:
i have custom user control and i'm trying to pass values to custom user control......I need help it seems to me i cannot pass the value to user control from dropdownlist. I have property in a...
2
by: Hari | last post by:
Hi I have an ASP.NET application that writes to a log file in a directory outside the webapp directory (e.g. c:\program files\myapp\logs). OS is Windows 2003 If I see the list of users in the...
1
by: Daniel Frede | last post by:
Hello, I Created a AxSHDocVw.AxWebBrowser in a class and want to Post Values to a WebPage. When I use this class in a Windows application, everything is fine, but in an ASPX page it hangs...
4
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once...
6
by: Dariusz Tomon | last post by:
Hi How can I get url of page so taht I can pass it to string varaible. I have got several urls in my IIS under one folder. I want to have one default.aspx where code under it recognize which...
13
by: mirandacascade | last post by:
I want to set things up such that a section of code will have been executed by the time one clicks on the drop down arrow on a combo box control. Currently, that section of code resides in the...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.