470,626 Members | 2,175 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,626 developers. It's quick & easy.

Master pages

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

Sep 18 '07 #1
3 2530
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.G etType(),"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.

Sep 18 '07 #2
Why not use the URL of the Request? It will contain the Page file name.

--
HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Adi" <gv*****@gmail.comwrote in message
news:11**********************@22g2000hsm.googlegro ups.com...
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

Sep 19 '07 #3
Adi
hey thanks guys.. tat helped me a lot..

Vijay

Sep 21 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sasha | last post: by
5 posts views Thread by Michael Herman \(Parallelspace\) | last post: by
17 posts views Thread by Rob R. Ainscough | last post: by
7 posts views Thread by xkeops | last post: by
3 posts views Thread by Rich | last post: by
6 posts views Thread by Mickey | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.