Creating Menu controls on the fly

R

ree32

I am reading off menu items from an XML file.

The problem I have is how to create these menu items into link buttons
on the fly. As the number of menu items will vary depending on the
contents of the xml file. So I cannot initialise these all these link
buttons one by one at start.

So I was wondering whether there was a way to dynamically create them?
 
J

Joerg Jooss

ree32 said:
I am reading off menu items from an XML file.

The problem I have is how to create these menu items into link buttons
on the fly. As the number of menu items will vary depending on the
contents of the xml file. So I cannot initialise these all these link
buttons one by one at start.

So I was wondering whether there was a way to dynamically create them?

If all you need are simple hyperlinks, you could use the Xml WebControl and
apply an XSLT transformation to create HTML directly from your XML source.

If you need to have server controls, you could write a composite control
that parses the XML file and creates a LinkButton for each entry of the XML
file in CreateChildControls(), but there are some tricky things to consider
when using the second approach. Do you need server controls?

Cheers,
 
R

ree32

Server controls would be needed. As what I am trying to build
something similar to a tree structure menu. So I need menu items to
collapse depending on whether a toggle switch has been pressed.

I will go and and read more about composite controls to see if its
applicable to my case.
 
J

Joerg Jooss

ree32 said:
Server controls would be needed. As what I am trying to build
something similar to a tree structure menu. So I need menu items to
collapse depending on whether a toggle switch has been pressed.

I will go and and read more about composite controls to see if its
applicable to my case.

Composite controls are just a special breed of server controls. Instead of
creating markup language output in Render(), you create child server
controls in CreateChildControls(). A keypad composed of Button controls is a
good example.

Cheers,
 

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

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top