trouble linking A menu control using sitemap datasource to MultiView Control?

Last post 10-10-2007 11:12 AM by dwilliams459. 2 replies.

Sort Posts:

  • Confused [8-)] trouble linking A menu control using sitemap datasource to MultiView Control?

    10-08-2007, 12:40 PM
    • Member
      point Member
    • dfour2
    • Member since 10-08-2007, 4:32 PM
    • Posts 2

    Having trouble linking A menu control using sitemap datasource
    to MultiView and View Web Server Controls

     

    I need CustMultview( the multiview control) to use method SetActiveView
    to get ViewID called from Menucontrol using selected menuitem Title or NavigateUrl

    I know I need to add
    // if (!IsPostBack)
    // {

    I want  (e.Item.text) to equal View view

     so I can utilize

    // CustMultview.SetActiveView(view)

    // to set the View ID

    or should  I use
    // protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
    // {
    // MultiView1.ActiveViewIndex = Int32.Parse(e.Item.Value);

    ? I not sure if I am making any sense.
    all the Details are below. I would appreciate some assistance ASAP

    [code-behind file- Browse2.aspx.cs]

     

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class Customer_Browse2_aspx : System.Web.UI.Page
    {
        protected void btnleft_MenuItemClick(Object sender, MenuEventArgs e)
        {
        // here is the problem!!
        }

    }

     

     

    [Sitmap file]

    <?xml version="1.0" encoding="utf-8" ?>
    <siteMap >
     <siteMapNode title="Home" url="Customer/Cust_home.aspx">
      <siteMapNode title="Consumables" url="Customer/browse2.aspx?Consumables" />
      <siteMapNode title="Services" url="Customer/browse2.aspx?Services" >
      </siteMapNode>
      <siteMapNode title="Training" url="Customer/browse2.aspx?Training" />
      <siteMapNode title="Support" url="Customer/browse2.aspx?Support" >
      </siteMapNode>
     </siteMapNode>
    </siteMap>

     

     

    [menu control]

    <div class="stripes" style="left: 0px; top: 10px">
      </div>
      <div class="btnbar">
      <asp:menu id="btnleft" runat="server"
        datasourceid="SiteMapDataSource1"
        cssclass="btnleft"
        orientation="Horizontal"
        maximumdynamicdisplaylevels="0"
        Target=""
        skiplinktext=""
        staticdisplaylevels="2" BorderColor="#999999" BorderStyle="Solid" BorderWidth="0px"
        OnMenuItemClick="btnleft_MenuItemClick" >
                <DynamicMenuItemStyle BorderStyle="None" />
                <StaticMenuItemStyle CssClass="btnon" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalPadding="0px" ItemSpacing="0px" />
                <StaticHoverStyle CssClass="btnon" BorderStyle="Solid" BorderColor="#999999" BorderWidth="1px" />
                <StaticSelectedStyle BackColor="White" />
               
            </asp:menu>

     


    [Multiview control]

       <asp:MultiView ID="CustMultiView" runat="server" ActiveViewIndex=0>
         
       <asp:View ID="Consumables" runat="server">
       // content......
       
       </asp:View>
         
          
       <asp:View ID="Services" runat="server">
          
       // content......
           </asp:View>
         
         
       <asp:View ID="Training" runat="server">
       // content......
        
       </asp:View>
         
       <asp:View ID="Support" runat="server">
       // content......
         
              </asp:View>

      </asp:MultiView>

  • Re: trouble linking A menu control using sitemap datasource to MultiView Control?

    10-10-2007, 2:30 AM

    Hi,

    Base on your description, you want to  change the MultiView's ActiveViewIndex in the menuItem click event, but the menuItenm click  event cannot be fired, right? 

    In fact, If the menuitem's navigateURL or URL is not null or empty, when you click on it , the page will be redirect to the new page directly without postback, so the menuitem event be fired.

    So, you can try to do like this:

    1. Add the menuitems in the aspx file not use the sitemap, because if the sitemapnode's url 's empty, the menuitem is unclickable.

    <asp:Menu ID="Menu1" runat="server" OnMenuItemClick="Menu1_MenuItemClick">
                            <Items>
                                <asp:MenuItem  Text="Home"  Value="1">
                                </asp:MenuItem>
                                <asp:MenuItem  Text="About" Value="2">
                                </asp:MenuItem>
                            </Items>
                        </asp:Menu>

     2. Redirect the new page in the codebehind:

     protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
        {
            if (e.Item.Text == "Home")
            {
                MultiView1.ActiveViewIndex = Int32.Parse(e.Item.Value);
    
                Response.Redirect("~/MenuEvent/CAse/Default.aspx");
            }
        }
      Hope it helps.
    Amanda Wang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: trouble linking A menu control using sitemap datasource to MultiView Control?

    10-10-2007, 11:12 AM
    Answer
    • Member
      73 point Member
    • dwilliams459
    • Member since 03-01-2006, 11:24 AM
    • Charlotte, NC
    • Posts 37

    As an alternative, I am doing the following:  You can add a Query string parameter to the target url, then assign the View index on form load.  If your MenuControl is encapsulated in a usercontrol or on a Master page, this should give you the flexibility to move Multiview items to separate pages.  In my case the page I am modifying has grown very large, and I want the ability to break it up. 
    Update: I am not currenlty using a sitemap, but a seperate XML file with a 'pagemode' attribute mapped to 'Value'.  I image the 'pagemode' attribute could be added to the existing sitemap, however I am uncertain if it can be mapped.  If not perhaps you can get the XmlElement in the code below. 

        Public Property MenuPageMode() As String
            Get
                Return ViewState("MenuPageMode")
            End Get
            Set(ByVal value As String)
                ViewState("MenuPageMode") = value
            End Set End Property Private Sub mnuLeftNavigation_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
                Handles mnuLeftNavigation.Load
            Dim reqPM As String = Request("pagemode")
            If Len(reqPM) > 0 Then MenuPageMode = reqPM Else
                MenuPageMode = 2
            End If
        End Sub
    
        Private Sub mnuLeftNavigation_MenuItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) _
                Handles mnuLeftNavigation.MenuItemDataBound
            'Dim xePage As XmlElement = CType(e.Item.DataItem, XmlElement) ' Use XmlElement if no Value
            e.Item.NavigateUrl = String.Format("{0}?pagemode={1}", e.Item.NavigateUrl, e.Item.Value) 
            If e.Item.Value = MenuPageMode Then e.Item.Selected = True
        End Sub
    
      
    David Williams MCP
    .Net Senior Developer
Page 1 of 1 (3 items)