473,657 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1861
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. IUserControlDes ignerAccessor.I nnerText." 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(f alse)

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.

#ParseChildrenA ttribute 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:
LiteralControlB uilder to let the ControlBuilder capture the content into
the "Text" property. Hence we need another attribute:

2) [ControlBuilder( typeof(LiteralC ontrolBuilder))]

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

#ControlBuilder Attribute 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(f alse)]
[ControlBuilder( typeof(LiteralC ontrolBuilder))]
public partial class WebUserControl : System.Web.UI.U serControl,
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
15099
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 the field values and write them to an ASCII file on the hard drive. Can anyone confirm that this is even possible? I have dredged up one article "Accessing the Internet Explorer Document Object Model from Visual Basic 5.0" (Asmi, 1998) that covers...
1
2991
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
3845
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 content of the IFRAME (that is inside the same page) depending > on which control the user presses. The chage would be triggered by the > control using a JavaScript. >
4
2260
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
3051
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 explorer would do in this case. The headers I am getting are: Headers {Content-Disposition: attachment; filename="dynamic_file.mdb" Connection: close Cache-Control: private Content-Type: application/octet-stream
5
2753
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" runat="server"> </asp:DropDownList> </ItemTemplate> </asp:TemplateField> I have the gridview inside of a master page- content hierarchy.
2
6978
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 header. I tried to put the link tag in the Master page, but the classes are not recognized in the Content Page. How do I use a StyleSheet with the Content Page? TIA
3
1566
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 controls, so I use the following statement to access them: Me.Page.FindControl(ControlID) However, this is returning Nothing, even though the control can be accessed in the Load event of the Page containing the control and the validator. I also...
5
2707
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 file is added by the webcontrol. This prevents me having to remember to add the CSS file to the page if I use a certain webcontrol. I have a MasterPage with an array of StyleSheets, and a public function for
0
8411
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
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8613
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
7351
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...
1
6176
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
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.