Reputation: 3
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). 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.
How can I pass a parameter from the first page to the master page of the second page?
Some code from first page:
.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
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
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);
}
}
Upvotes: 0
Views: 269
Reputation: 3
I solved it by getting the url of the content page in page load event in the master page.
MasterPage.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;
}
}
Upvotes: 0