Content within a user control

I am almost embarrassed to ask this question, but here we go ...

I am not an expert with user controls and do not need design advice on how to try to achieve a certain desired functionality.

The goal is to have a usercontrol that will display as a complex structure of html and css elements to form an elegant container box. The problem is how to populate the contents of the window, as each instance of usercontrol will have its own separate HTML content. The contents of the usercontrol div container will be nested in the structure of the displayed html. It is undesirable to program user control content or use properties.

In the psuedo code, the desired syntax would look something like this:

<usercontrol Title="Some Title"><p>some random html content</p></usercontrol> 

Sample visualized user controls:

 <div class="CommonBox"> <div class="Title">Some Title</div> <div class="Content"><p>some random html content</p></div> </div> 

Hope my explanation is enough. Does it make sense to anyone or is the desired functionality unattainable?

Hooray!

EDIT

I tried to offer boilerplate user management in the hope of coming up with a decent solution. I "backbacked" this site and now has a working template user control. My next question is: how can I programmatically access the controls embedded in the template ... let's say there is a text box control in the Description template from the link to the example, and I want to set its value programmatically? Is it possible?

+4
source share
3 answers

What you are looking for is definitely possible. One solution is to create a templated user control . In the end, you can define content similar to what your example looks like. Sort of:

 <uc:MyControl Title="Some TItle" runat="server"> <ContentsTemplate> <p>some random html content</p> </ContentsTemplate> </uc:MyControl> 

Here is an easy way . I have done this in the past with success. There are many resources found through Google , as well as on this topic.

+3
source

Yes, it is very possible. You can first create a custom control, as I will describe in this post. The properties in the control become attributes of the type "Title" that you have in your example. You can then expand your control using the method shown in this post to add child nodes for other html inputs that you will need.

Enjoy it!

0
source

It looks like you need two properties for user server management.

The title property to render the first internal content of the div,

Content for the second. If you want to set the content inside your server control, you must use the [PersistenceMode(PersistenceMode.InnerDefaultProperty)] attribute for your property, for example:

 [PersistenceMode(PersistenceMode.InnerDefaultProperty)] public string Contents { get { string contents = (string)ViewState["Contents"]; return (contents == null) ? String.Empty : contents; } set { ViewState["Contents"] = value; } } 

PersistenceModeAttribute is explained in MSDN as follows:

PersistenceModeAttribute Pass The InnerDefaultProperty parameter specifies that the visual designer should retain the property to which the attribute is applied as an internal default. This means that the visual designer stores the property in control tags. an attribute can be applied to only one property, since only one property can be stored within the tag. The value of the property is not wrapped in a special tag.

For more information, see the latest example here .

0
source

All Articles