Master pages

A

Adi

Hi all,

I have a menu which is placed in the master page. Now when the user
clicks on one of the menu item, it fires an event which is handled in
the master page. I need to know from which page the menu item was
clicked is there any way i can get the id of the page and verify it or
is there an alternate way to do it. I have recently started using
master pages in my website. previously I was having the menu control
in a web user control(.ascx), where i used to get the page id by using
Parent.Id.. in the master pages i get it as "__Page".

To be clear i have Banner.Master which has the menu control
i have the content page a.aspx and another content page b.aspx
when the user clicks on the menu item in page a.aspx then only it
should redirect it to b.aspx otherwise it shouldnt do anything.. or do
a simple post back.

i am using asp.net v2.0.

please let me know if you need further information.

thanks
Vijay
 
D

Donn Felker

You could access the page by doing the following.

Wire up the MenuItemClick event handler.

Like so: (this is in the master page's cs file)

protected void testMenu_MenuItemClick(object sender, MenuEventArgs e)
{
string pageName = (sender as
Menu).Page.AppRelativeVirtualPath;

// Display it to you as a js pop up

Page.ClientScript.RegisterClientScriptBlock(Page.GetType(),"alert",
string.Format("alert('Page: {0}');", pageName),true);
}

In the Master Page, you'd have this:

<asp:Menu runat="server" ID="testMenu"
OnMenuItemClick="testMenu_MenuItemClick">
<Items>
<asp:MenuItem Text="Link1" Value="1"></asp:MenuItem>
<asp:MenuItem Text="Link2" Value="=2"></asp:MenuItem>
</Items>
</asp:Menu>

I hope that helps you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top