【问题标题】:How do I get the menu item value from the site master page to a another page如何从站点母版页获取菜单项值到另一个页面
【发布时间】:2019-06-13 20:02:16
【问题描述】:

我有一个菜单,它在我的母版页上有子菜单。当菜单打开第二个窗口时,我想知道用户选择了哪个选项。例如:顶级菜单是“编辑现有项目”。子选项为“修改商品状态;修改商品描述;修改商品HTS代码。

我已经尝试了过去七个小时内发现的几乎所有文章和建议。

在站点主人上:

<asp:Menu ID="NavigationMenu0" runat="server" CssClass="auto-style7" 
EnableViewState="False" IncludeStyleBlock="False" 
Orientation="Horizontal" 
Height="16px" style="margin-left: 20px" Width="215px" BackColor="#99CCFF" 
DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="Small" 
ForeColor="#284E98" StaticSubMenuIndent="10px" 
OnMenuItemClick="NavigationMenu0_MenuItemClick" >
    <DynamicHoverStyle BackColor="#284E98" ForeColor="White" />
    <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
    <DynamicMenuStyle BackColor="#B5C7DE" />
    <DynamicSelectedStyle BackColor="#507CD1" />
    <Items>
        <asp:MenuItem Text="Edit Existing Item" ToolTip="Edit Item already in GP" Value="Edit Existing Item">
        <asp:MenuItem Text="Change Item  Status" ToolTip="Change the status of an item" Value="S" ></asp:MenuItem>
        <asp:MenuItem Text="Edit Item Description" ToolTip="Edit the description of an Item" Value="D"></asp:MenuItem>
        <asp:MenuItem Text="Change HTS Code" ToolTip="Change the HTS Code of an Item" Value="H"></asp:MenuItem>
    </Items>

母版页后面的代码是:

protected void NavigationMenu0_MenuItemClick(Object sender, MenuEventArgs e)
//get the menu option selected by the user
{
    var menu = (sender as Menu);
    //ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('Selected Menu is : " + menu + "')", true);

    foreach (MenuItem item in menu.Items)
    {
        System.Diagnostics.Debug.Print(item.Text);
    }
    var clickedMenuItem = e.Item;
    Session["1"] = e.Item.Text;
    Response.Redirect("~/ChangeItem.aspx?=" + e.Item.Text);
}

根据我的阅读,获取菜单值的最佳方法是 在我的 ChangeItemPage 上,我有以下内容:

protected void NavigationMenu0_MenuItemClick(Object sender, MenuEventArgs e)
//get the menu option selected by the user
{
    string ChgItemType = Request.QueryString["value"];
    WebMsgBox.Show("The Menu Item is: " + ChgItemType);
}

作为测试,我也有它: protected void Page_Load(object sender, EventArgs e) { txtItemSearch.Focus();

    //var menux = (sender as Menu).SelectedValue;
    string ChgItemType = Request.QueryString["value"];
    WebMsgBox.Show("The Menu Item is: " + ChgItemType);
}

ChangeItemType 值为 NULL。

【问题讨论】:

  • 如果我将鼠标悬停在这条线上:

标签: c#


【解决方案1】:

我找到了答案。 改变 Response.Redirect("~/ChangeItem.aspx?=" + e.Item.Text);到 Response.Redirect("~/ChangeItem.aspx?value=" + e.Item.Value);解决了。​​

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多