Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1465
Refreshing Menu from XML source
posted

Hello.

I'm using 8.1, the UltraWebMenu control, and binding to abn XML Datasource.

The acutal menu items are stored in a database, which are returned as a DataSet, converted to XML and transformed to another XML doc and bound to the XmlDatasource object. Everything works fine.

The problem is refreshing the menu. Perodically the XmlDatasource is repopulated (refreshed) but the UltraWebMenu doesn't reflect the updated XML doc. Here's the code from the page that is hosting the UltraWebMenu (both the XmlDatasource and UltraWebMenu controls have their EnableViewState property set to False):

Partial Public Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   Me.XmlDataSource1.Data = Application("MenuXML").ToString()  ' This is the new XML doc retrieved from the database
   Me.XmlDataSource1.DataFile = ""
   Me.XmlDataSource1.XPath = "/root/item[@MenuName='MNUMASTERTOP']"
   Me.XmlDataSource1.DataBind()
End Sub

Private Sub UltraWebMenu1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles UltraWebMenu1.PreRender
   Me.UltraWebMenu1.Items.Clear()
   Me.UltraWebMenu1.DataSourceID = ""
   Me.UltraWebMenu1.DataSource = Me.XmlDataSource1
   Me.UltraWebMenu1.DataBind()
End Sub

End Class

Any ideas?

Thanks in advance,

Mike 

Parents
  • 28464
    posted

    Really weird, since I originally thought this is a bug in UltraWebMenu. Then I've tried the same with the built-in asp:menu with pretty much the same results (Menu1 is asp:menu):

        protected void UltraWebMenu1_PreRender(object sender, EventArgs e)
        {
            UltraWebMenu1.Items.Clear();
            UltraWebMenu1.DataSourceID = "XmlDataSource1";
            UltraWebMenu1.DataBind();

            Menu1.Items.Clear();
            Menu1.DataSourceID = "XmlDataSource1";
            Menu1.DataBind();
        }

    I'd say, this has something to do with XmlDataSource being a declarative datasource control and it does not play nicely with code-behind and the lifecycle of the page. UltraWebMenu does provide support for binding directly to related DataTables inside a DataSet, so if you have this structure, why not try binding directly to this DataSet using the UltraWebMenu1.DataSource property? 

Reply Children