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

Accessing Content INSIDE a Web Control

Hi. If I create a WebControl (User Control, actually), I know how, easily, to
access the design-time Properties that have been set as Propertiy nodes in
the tag used on the ASPX page. But I've never tried having CONTENT inside my
Control's Tag, e.g.:

<Ax:MyCtl id="Something" runat="server">
Some stuff inside the tag
</Ax:MyCtl>

How do I access the body from the code of my Control (i.e. above, "Some
stuff inside the tag")?

Thanks.

Alex
Aug 3 '06 #1
5 1849
Hi,

Alex Maghen wrote:
Hi. If I create a WebControl (User Control, actually), I know how, easily, to
access the design-time Properties that have been set as Propertiy nodes in
the tag used on the ASPX page. But I've never tried having CONTENT inside my
Control's Tag, e.g.:

<Ax:MyCtl id="Something" runat="server">
Some stuff inside the tag
</Ax:MyCtl>

How do I access the body from the code of my Control (i.e. above, "Some
stuff inside the tag")?

Thanks.

Alex
I might be wrong (I don't usually do user controls, only custom
controls), but isn't the content ("children") of a control placed in the
Controls collection? This is what happens for Custom controls at least.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 3 '06 #2
Hi. Well, my UserControl *does* have a Controls collection property, but I
really don't know where to go from there. I mean, the text inside the
opn/close tag of my control isn't really a control, right? It's just the body
text. How do I get to that?

Alex
"Laurent Bugnion" wrote:
Hi,

Alex Maghen wrote:
Hi. If I create a WebControl (User Control, actually), I know how, easily, to
access the design-time Properties that have been set as Propertiy nodes in
the tag used on the ASPX page. But I've never tried having CONTENT inside my
Control's Tag, e.g.:

<Ax:MyCtl id="Something" runat="server">
Some stuff inside the tag
</Ax:MyCtl>

How do I access the body from the code of my Control (i.e. above, "Some
stuff inside the tag")?

Thanks.

Alex

I might be wrong (I don't usually do user controls, only custom
controls), but isn't the content ("children") of a control placed in the
Controls collection? This is what happens for Custom controls at least.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 3 '06 #3
ALSO, I found in the documentation for UserControls, under "Explicit
Interface Implementations" (whatever that means),
"System.Web.UI.IUserControlDesignerAccessor.InnerT ext." That looks perfect,
but I have no idea how you call it.

Alex
"Alex Maghen" wrote:
Hi. Well, my UserControl *does* have a Controls collection property, but I
really don't know where to go from there. I mean, the text inside the
opn/close tag of my control isn't really a control, right? It's just the body
text. How do I get to that?

Alex
"Laurent Bugnion" wrote:
Hi,

Alex Maghen wrote:
Hi. If I create a WebControl (User Control, actually), I know how, easily, to
access the design-time Properties that have been set as Propertiy nodes in
the tag used on the ASPX page. But I've never tried having CONTENT inside my
Control's Tag, e.g.:
>
<Ax:MyCtl id="Something" runat="server">
Some stuff inside the tag
</Ax:MyCtl>
>
How do I access the body from the code of my Control (i.e. above, "Some
stuff inside the tag")?
>
Thanks.
>
Alex
I might be wrong (I don't usually do user controls, only custom
controls), but isn't the content ("children") of a control placed in the
Controls collection? This is what happens for Custom controls at least.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 3 '06 #4
Hi,

Alex Maghen wrote:
Hi. Well, my UserControl *does* have a Controls collection property, but I
really don't know where to go from there. I mean, the text inside the
opn/close tag of my control isn't really a control, right? It's just the body
text. How do I get to that?

Alex
All Controls have a Controls collection, it's inherited from the Control
class from which all Controls (User controls and Custom controls, as
well as built in controls) derive.

You must understand the hierarchical nature of HTML. It's like XML.
Everything is contained in something, from single text up to the
document. Even text is a control, in HTML it will be rendered in a text
node (which, when rendered, displays just text).

This hierarchical structure is reflected in ASP.NET, where Controls have
children and parents.

That said, I am confused. I tried to reproduce this from your original post:

<Ax:MyCtl id="Something" runat="server">
Some stuff inside the tag
</Ax:MyCtl>

Turns out this is illegal, and on my VS2005, it won't even run, stating
that placing content in the tag is not allowed.

OK, the easiest for you is to set a breakpoint in your page's
codebehind, and then to look what is in the Controls collection. Try to
navigate the hierarchy, until you find the text you want to access...

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 4 '06 #5
Hi Alex,

To capture the content inside your UserControl tags, you need to add
following two attributes to your UserControl:

1) ParseChildren(false)

This will instruct the parser to interpret the elements that are contained
within the server control's tags as content that will be parsed with an
associated ControlBuilder, that is, as controls.

#ParseChildrenAttribute Class
http://msdn2.microsoft.com/en-us/lib...ildrenattribut
e.aspx

With default ControlBuilder, the content will be added to your
UserControl's Controls collection as a literal control. Based on my
research, it seem this literal control is always added as the last control.
So you could use Controls[Controls.Count-1] to access it.

But we can also utilize the LiteralControl's ControlBuilder:
LiteralControlBuilder to let the ControlBuilder capture the content into
the "Text" property. Hence we need another attribute:

2) [ControlBuilder(typeof(LiteralControlBuilder))]

This will assign the LiteralControlBuilder to your UserControl. We also
need to implement interface ITextControl to provide a Text property.

#ControlBuilderAttribute Class
http://msdn2.microsoft.com/en-us/lib...builderattribu
te.aspx

#ControlBuilder Class
http://msdn2.microsoft.com/en-us/lib...olbuilder.aspx

Here's a complete code listing of the Code-Behind class of UserControl:

[ParseChildren(false)]
[ControlBuilder(typeof(LiteralControlBuilder))]
public partial class WebUserControl : System.Web.UI.UserControl,
ITextControl
{
#region ITextControl Members
public string Text
{
get
{
object text = ViewState["Text"];
if (text == null) return string.Empty;
return text as string;
}
set
{
ViewState["Text"] = value;
}
}
#endregion
}

Hope this helps. Please feel free to post here if anything is unclear.
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.

Aug 4 '06 #6

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

Similar topics

3
by: Tom Meuzelaar | last post by:
Hello: I'm using VB6 in VS enterprise. I'd like to place an HTML form inside a VB container, have a user fill out the form information, click a submit button, and then have the program capture...
1
by: Julius Mong | last post by:
Dear all, I have something like this: <html... > <embed ...> </html> Am I out of luck if I wanted to access the embedded DOM and manipulate its content? Or if I have:
2
by: Tom Szabo | last post by:
"Tom Szabo" <tom@intersoft.net.au> wrote in message news:419fe530$1@dnews.tpgi.com.au... > Hi All, > > I have a page and inside the page I have an IFRAME. From the page I like to > change the...
4
by: Moojjoo | last post by:
Ok fellow C# developers: How do creat an instance of an object inside a dataset or datagrid. Example I need to have a placeholder inside a dataset. Any help would be great.
5
by: Daniel Corbett | last post by:
I am trying to save a file dynamically created in a webpage. I get the following headers, but cannot figure out how to save the attachment. I am basically trying to replicate what internet...
5
by: Siva | last post by:
Hello I have a dropdownlist inside the gridview as a template column defined as follows: <asp:TemplateField HeaderText="Choose Location"> <ItemTemplate> <asp:DropDownList ID="ddlChooseLoc"...
2
by: SR | last post by:
I have started a web site using ASP.NET 2.0. I would like to centralize all of my classes in a StyleSheet but I cannot figure out how to link the StyleSheet to a Content Page since there is no...
3
by: Nathan Sokalski | last post by:
I have a validator that I wrote by inheriting from BaseValidator. At certain points in the code, I need to access other controls on the page containing the validator. I have the IDs of these...
5
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys I'm trying to make my code as streamlined as possible, and add CSS file references dynamically when they are required, for example, if a page contains a webcontrol, then the related CSS...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
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...

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.