473,805 Members | 2,297 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>thi s is a simple text</c01:MyCtrl>.

The control-code:

[DefaultProperty ("Text02")]
[ToolboxData("<{ 0}:MyCtrl runat=server></{0}:MyCtrl>")]
[PersistChildren (true)]
[ParseChildren(f alse)]
.... MyCtrl .... inhereted from Control (not from WebControl)
............... ...
//the property which should be used for the innertext.
[Category("Appea rance")]
[DefaultValue("" )]
[Localizable(tru e)]
[PersistenceMode (PersistenceMod e.InnerDefaultP roperty)]
public string Text02
{
get
{
String s = (String)ViewSta te["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 2405
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 "ParseChildrenA ttribute" as "true", this
indicate that the inner content of the control tag will be parsed as
control properties.

#ParseChildrenA ttribute Class
http://msdn2.microsoft.com/en-us/lib...ildrenattribut
e.aspx
2) The "PersistChildre nAttributeA" is used together with the
"parseChildrenA ttribute", from the MSDN document remark below:

=============== ====
The PersistChildren Attribute is used in combination with the
ParseChildrenAt tribute to determine how nested content of a control is
interpreted. If PersistChildren Attribute is true and ParseChildrenAt tribute
is false, the nested content contained within an ASP.NET server control is
persisted as controls.If PersistChildren Attribute is false and
ParseChildrenAt tribute 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 "PersistChildAt tribute" to false and
"ParseChildrenA ttribute" to true. e.g.

[ParseChildren(t rue,"Descriptio n")]
[PersistChildren (false)]
Here is a complete test control for your reference:

=============== =============== ====
[DefaultProperty ("Descriptio n")]
[ToolboxData("<{ 0}:PropertyCont rol
runat=server></{0}:PropertyCon trol>")]
[ParseChildren(t rue,"Descriptio n")]
public class PropertyControl : WebControl
{
[Bindable(true)]
[Category("Appea rance")]
[DefaultValue("" )]
[Localizable(tru e)]
public string Text
{
get
{
String s = (String)ViewSta te["Text"];
return ((s == null) ? String.Empty : s);
}

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

[Bindable(true)]
[Category("Appea rance")]
[DefaultValue("d efault description")]
[Localizable(tru e)]
[PersistenceMode (PersistenceMod e.InnerDefaultP roperty)]
public string Description
{
get
{
String s = (String)ViewSta te["Descriptio n"];
return ((s == null) ? String.Empty : s);
}

set
{
ViewState["Descriptio n"] = 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.coms chrieb im Newsbeitrag
news:44******** ******@TK2MSFTN GXA01.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 "ParseChildrenA ttribute" as "true", this
indicate that the inner content of the control tag will be parsed as
control properties.

#ParseChildrenA ttribute Class
http://msdn2.microsoft.com/en-us/lib...ildrenattribut
e.aspx
2) The "PersistChildre nAttributeA" is used together with the
"parseChildrenA ttribute", from the MSDN document remark below:

=============== ====
The PersistChildren Attribute is used in combination with the
ParseChildrenAt tribute to determine how nested content of a control is
interpreted. If PersistChildren Attribute is true and
ParseChildrenAt tribute
is false, the nested content contained within an ASP.NET server control is
persisted as controls.If PersistChildren Attribute is false and
ParseChildrenAt tribute 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 "PersistChildAt tribute" to false and
"ParseChildrenA ttribute" to true. e.g.

[ParseChildren(t rue,"Descriptio n")]
[PersistChildren (false)]
Here is a complete test control for your reference:

=============== =============== ====
[DefaultProperty ("Descriptio n")]
[ToolboxData("<{ 0}:PropertyCont rol
runat=server></{0}:PropertyCon trol>")]
[ParseChildren(t rue,"Descriptio n")]
public class PropertyControl : WebControl
{
[Bindable(true)]
[Category("Appea rance")]
[DefaultValue("" )]
[Localizable(tru e)]
public string Text
{
get
{
String s = (String)ViewSta te["Text"];
return ((s == null) ? String.Empty : s);
}

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

[Bindable(true)]
[Category("Appea rance")]
[DefaultValue("d efault description")]
[Localizable(tru e)]
[PersistenceMode (PersistenceMod e.InnerDefaultP roperty)]
public string Description
{
get
{
String s = (String)ViewSta te["Descriptio n"];
return ((s == null) ? String.Empty : s);
}

set
{
ViewState["Descriptio n"] = 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
2442
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 code it is 50% chance that the update will make it back to the dataset. If I update the dataset instead of the form, it does not show on the form. Is there a method that should be used?
6
3419
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 sized strangely using the .RTFHeight property of the control. Specifically, lines of text get cut off the bottom of the control when I use the code provided in the sample report on the lebans.com site. It seems that when there is Chinese text,...
9
3976
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 will not set the value of the control and will leave the checked status of the checkbox to false when a user selects a new date. this works fine when using the control on a win2k machine but if we use it on a win XP box and call
0
1910
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 control. In a default.aspx page <SkinExample:Hello id="HelloControl" SkinName="red" runat="server" /> i can pass the value, it works fine, but from the dropdownlist in a codebehind page i can't pass the value. Could some one help me out with...
2
1316
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 "Security" tab for the 'logs' directory, I see that <localmachine>\Users already exists. Now, <localmachine>\ASPNET is a part of this 'Users' group. But this group does not have write access to the 'logs' directory. I think this is the default setting...
1
3698
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 after the .submit (see code) Even if i try to start the class in a new thread it terminates at the ..submit
4
2520
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 I have exposed a public property containing the value of a textbox in a user control..how do I grab this from the calling page? I cant think of the syntax, since my page doesnt know the contents of the class (and therefore, the public...
6
29656
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 url is used by user and then display appropriate data to that url (one url is about fashion, other about law and so on). By means of recognition of url I can display appropriate banners for example.
13
8643
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 OnGetFocus event of the combo box control, and this appears to work...I'm guessing because one cannot click on the drop down arrow of a combo box control without first having the combo box control receive focus. But I noticed that the code gets...
0
9718
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
9596
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
10617
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
10109
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
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5545
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3849
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
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.