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
Donn Felker - 18 Sep 2007 23:56 GMT
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.
Adi - 21 Sep 2007 14:29 GMT
hey thanks guys.. tat helped me a lot..
Vijay
Kevin Spencer - 19 Sep 2007 14:07 GMT
Why not use the URL of the Request? It will contain the Page file name.

Signature
HTH,
Kevin Spencer
Microsoft MVP
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
> Hi all,
>
[quoted text clipped - 19 lines]
> thanks
> Vijay