Menu - Pass Value

J

Joao Batista

Hi all,

I have a MasterPage with a menu, populated from a database, my problem now
is when i chose an option , how can i pass (catch) the value to my products
page???

Thanks

Joao Batista
 
J

Joao Batista

Hi Ken,
i'm a newbie here, I know that (and i can get the reference to the menu),
but i don't know how to get reference to the selected item, have you some
example where i can see that.

Thank's

Joao Batista


Ken Cox - Microsoft MVP said:
Hi Joao,

You need to get a reference to the master page using FindControl and with
that, get a reference to the menu. The menu reference should give you its
select item name or id.

Here's where to start:

http://msdn2.microsoft.com/en-us/library/xxwa0ff0(VS.80).aspx

Ken
Microsoft MVP [ASP.NET]

Joao Batista said:
Hi all,

I have a MasterPage with a menu, populated from a database, my problem
now is when i chose an option , how can i pass (catch) the value to my
products page???

Thanks

Joao Batista
 
K

Ken Cox - Microsoft MVP

Here's the master:

<%@ Master Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{
Label mpLabel;
mpLabel= (Label)this.ContentPlaceHolder1.FindControl("Label1");
if (mpLabel != null)
{
mpLabel.Text = Menu1.SelectedItem.Text;
}
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Menu Master</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:menu id="Menu1" runat="server" orientation="Horizontal"
onmenuitemclick="Menu1_MenuItemClick">
<items>
<asp:menuitem text="Colour" value="Colour">
<asp:menuitem text="Red" value="Red"></asp:menuitem>
<asp:menuitem text="Green" value="Green"></asp:menuitem>
<asp:menuitem text="Blue" value="Blue"></asp:menuitem>
</asp:menuitem>
<asp:menuitem text="Animal" value="Animal">
<asp:menuitem text="Dog" value="Dog"></asp:menuitem>
<asp:menuitem text="Cat" value="Cat"></asp:menuitem>
<asp:menuitem text="Pig" value="Pig"></asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
</div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</form>
</body>
</html>

Here's the page:

<%@ Page Language="C#" MasterPageFile="~/menu.master" Title="Catch Menu" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<br />
<asp:label id="Label1" runat="server" text="Label"></asp:label>
</asp:Content>


When the menu is selected. it finds the contentplaceholder and the label and
sets the text.

Okay?

Ken

Joao Batista said:
Hi Ken,
i'm a newbie here, I know that (and i can get the reference to the menu),
but i don't know how to get reference to the selected item, have you some
example where i can see that.

Thank's

Joao Batista


Ken Cox - Microsoft MVP said:
Hi Joao,

You need to get a reference to the master page using FindControl and with
that, get a reference to the menu. The menu reference should give you its
select item name or id.

Here's where to start:

http://msdn2.microsoft.com/en-us/library/xxwa0ff0(VS.80).aspx

Ken
Microsoft MVP [ASP.NET]

Joao Batista said:
Hi all,

I have a MasterPage with a menu, populated from a database, my problem
now is when i chose an option , how can i pass (catch) the value to my
products page???

Thanks

Joao Batista
 

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

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,201
Latest member
KourtneyBe

Latest Threads

Top