Web User Controls

J

Jonathan Wood

Okay, as evidenced by other questions, I am an experienced programmer very
new to ASP.NET.

I have a vertical navigation bar. It is all one color with several panels
inside it with a different color. It looks okay but I'm wondering if each of
these several panels should be Web User Controls themselves.

I think this would make sense, and I can figure out how to add a property
that specifies the image that appears at the top of each of these panels.
However, what I'm not sure about is how to handle the fact that each panel
can have any number of hyperlinks in it.

Is there a straight forward way to have a user control accept a list of
items (preferrably, within the IDE)?

Thanks!
 
H

Hans Baumann

Jonathan Wood said:
Okay, as evidenced by other questions, I am an experienced programmer very
new to ASP.NET.

I have a vertical navigation bar. It is all one color with several panels
inside it with a different color. It looks okay but I'm wondering if each
of these several panels should be Web User Controls themselves.

Yes you can. Actually I've done that, you can see in www.selered.com the
left vertical navigation bar is a web user control
I think this would make sense, and I can figure out how to add a property
that specifies the image that appears at the top of each of these panels.
However, what I'm not sure about is how to handle the fact that each panel
can have any number of hyperlinks in it.

I guess your control has two levels of navigation hieracy

You can seek this steps:
1 You can create a web control, inside you can put a repeater will all the
features you need, but make sure your repeater is populated by a dataset
public property (the second navigation level that reads the content from a
first level navigation field/id) in your web control. Also the image on the
top or your web control is referenced by another public property.
2 On your web form, you populate a repeater, datagrid, datalist, etc with a
dataset (or similar), containing the first navigation level. Make sure that
dataset has the field that is needed to get the second dependant level
3. Declare a public function in your web control, that recieves the first
navigation field value and return the dataset containing the whole second
level navigation.
4. In the item template of your repeater/datagrid/etc, insert the custom
control tag of your web user control, and declare the dataset public
property like this:

<myns:uxtag id="mywebusercontrol" runat="server"
MyDataSetProperty='<%#MyPublicFunction(DataBinder.Eval(Container.DataItem,
"myfield")%>' />

this will resolve the dataset at "render-time"

5. Fill your repeater/datagrid and "DataBind" it...

Another more simple way to acomplish this is using xml/xslt in a
LiteralControl... he he... choose the one you like most.... I've done both
of them, the xsl is only when I don't need to generate postbacks, the web
user control solution is more in a extense web app with reusable components
that generates events... etc.


Is there a straight forward way to have a user control accept a list of
items (preferrably, within the IDE)?

If you want that you have to create a custom control, which is more
complicated but more user-friendly at design time.

Hope I have been clear enough, enjoy!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top