简体   繁体   English

如何将参数从 aspx 页面传递到母版页以加载不同的菜单?

[英]How to pass a parameter from a an aspx page to a master page in order to load different menus?

I have a webforms page with a dropdownlist with projects and a "Go" button (first page).It has its own master page.我有一个带有项目下拉列表和“开始”按钮(第一页)的网络表单页面。它有自己的母版页。

When the user selects a Project from the list and clicks on "Go" I redirect to another home page according to the project selected.当用户从列表中选择一个项目并单击“开始”时,我会根据所选项目重定向到另一个主页。 When the project home page loads I would like to change the asp:menu items of that page according to what the user selected in the dropdown list of the first page (meaning according to the project).当项目主页加载时,我想根据用户在第一页下拉列表中选择的内容更改该页面的 asp:menu 项(意味着根据项目)。 So each project has its own asp navigation menu but I want to use the same master page for all the project home pages and not create different master pages for all the projects.所以每个项目都有自己的 asp 导航菜单,但我想为所有项目主页使用相同的母版页,而不是为所有项目创建不同的母版页。

How can I pass a parameter from the first page to the master page of the second page?如何将参数从第一页传递到第二页的母版页?

Some code from first page:第一页的一些代码:

.aspx .aspx

<div>
        <table width="250">
            <tr>
                <td align="left">
                    <dx:ASPxComboBox runat="server" ID="CmbProject" Height="20">
                        <Items>
                            <dx:ListEditItem Text="Project1" Value="0"></dx:ListEditItem>
                            <dx:ListEditItem Text="Project2" Value="1"></dx:ListEditItem>
                        </Items>
                    </dx:ASPxComboBox>
                </td>
                <td>
                    <dx:ASPxButton runat="server" ID="BtnGo" OnClick="BtnGo_Click" Text="Go">
                    </dx:ASPxButton>
                </td>
            </tr>
        </table>
    </div>

.cs 。CS

public partial class FirstPage: System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
 
    protected void BtnGo_Click(object sender, EventArgs e)
    {
        if (Convert.ToInt32(CmbProject.Value) == 0)
        {
            Response.Redirect("../Project1.aspx);
 
        }
        else if (Convert.ToInt32(CmbProject.Value) == 1)
        {
            Response.Redirect("../Project2.aspx);
        }
    }
}

I can pass a parameter with a query string to the second page but how the master page of the second page can get that parameter before loading the second page in order to load the corrent navigation menu?我可以将带有查询字符串的参数传递给第二页,但是第二页的母版页如何在加载第二页之前获取该参数以加载正确的导航菜单?

First page.cs第一页.cs


protected void BtnGo_Click(object sender, EventArgs e)
    {
        if (Convert.ToInt32(CmbProject.Value) == 0)
        {
            Response.Redirect("../Project1.aspx?Project=" + CmbProject.Text);
 
        }
        else if (Convert.ToInt32(CmbProject.Value) == 1)
        {
            Response.Redirect("../Project2.aspx?Project=" + CmbProject.Text);
        }
    }

I solved it by getting the url of the content page in page load event in the master page.我通过在母版页的页面加载事件中获取内容页的 url 来解决它。

MasterPage.cs母版.cs

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
            {
                string strPage = Page.AppRelativeVirtualPath;
                if (strPage.Contains("/Project1/"))
                {
                    PanelProject1.Visible = true;
                    PanelProject2.Visible = false;
                }
                else if (strPage.Contains("/Project2/"))
                {
                    PanelProject1.Visible = false;
                    PanelProject2.Visible = true;
                }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM