Class Menu problems


P

Paolo

Hi to everybody.

I need help with the usage of the Menu object in .net.

I developed a Menu control that reads the menu from an xml configuration
string stored in a DB.
The idea was to allow the insertion of my menu with the simple code:

<MY:MyMenu ID="Menu1" MenuSetName="FirstMenu" runat="server"></MY:MyMenu>



This row allows the menu to search in the DB the correct menu resources
(texts and links), and to Bind the menu to a runtime-created XmlDataSource.

MyMenu is defined as follow:

public class MyMenu : CompositeControl, INamingContainer

{

// Implementation not complete

protected override void OnLoad(EventArgs e)

{

if (!Page.IsPostBack || !Page.EnableViewState) {

BuildChildControls();

DataBind();

}

base.OnLoad(e);

}



protected void BuildChildControls ()

{

Menu menu = new Menu();

XmlDataSource xmlDS = new XmlDataSource();

// Fill the DataSource and the Menu controls with:
menu.DataBindings.Add(mib); Where mib is a properly-set MenuItemBinding

// Add the child controls to the Controls collection

base.Controls.Add(xmlDS);

base.Controls.Add(menu);

}

}



Well, everything works fine at the first page load, but doesn't work at
postbacks.

The menu is loaded, but only the MenuItems are valorized. The formatting is
lost, and also the XmlDataSource control is not reloaded correctly.

I think I have 2 main problems:

First: The control state is not properly saved/retrieved, so the child
controls (Menu and XmlDataSet) are not valorized on postback.

Second: The root menus have an empty NavigateUrlField, that results in an
empty postback to the same page. I'd like to deactivate this behaviour, but
I was unable to do it. Probably the xml structure I used is not the best I
could conceive. That's a point that I can try to solve by myself.

Do someone has an idea on how to solve the first issue?

Regards,

Paolo.
 
Ad

Advertisements


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

Top