Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Menu control issue....

Reply
Thread Tools

Menu control issue....

 
 
John Smith
Guest
Posts: n/a
 
      08-03-2006
I am trying to use the menu control for a tabbed menu system but it's
frustrating the hell out of me. The full code is listed below. The trouble
that I'm having is that, when the user clicks on a menu item, the page will
send back the id of the menu that was clicked. But it doesn't do that and I
can't figure out how to make it work. Looking at the code below, the
variable "strDBView" is always null. But it's a global variable and gets
assigned a value upon the menu click. I have tried putting that
Response.Write line in the !IsPostBack clause with the same results. If I
place the Response.Write line within the menu click event handler, it does
writes out a value as expected. So, it's like the value gets set and then,
upon page load, wiped out.

Any ideas? I have spent 4 days trying to figure this out.

Thanks in advance.

code follows:
<%@ Page 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">
string strDBView;

protected void Page_Load(object sender, EventArgs e)
{
string strMenuLabel;

// why is strDBView always null? I'm assigning it a value within
the menu control click evet
Response.Write("<br />Here: " + strDBView + "</br >");

if (!this.IsPostBack)
{
for (int index = 0; index < mvTicketMan.Views.Count; index++)
{
strMenuLabel =
mvTicketMan.Views[index].ID.ToString().Replace("vw", "").Replace("_", " ");
mnuTicketMan.Items.Add(new MenuItem(strMenuLabel,
index.ToString()));
}
mnuTicketMan.Items[0].Selected = true;
}
}

protected void mnuTicketMan_MenuItemClick(object sender, MenuEventArgs
e)
{
mvTicketMan.ActiveViewIndex = Int32.Parse(e.Item.Value);
strDBView =
mvTicketMan.Views[Int32.Parse(e.Item.Value)].ID.ToString().Replace("vw",
"").Replace("_", " ");
// if I show the value here, it does indeed get assigned a proper
value
//Response.Write("<br />Here: " + strDBView + "</br >");
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<link href="main.css" type="text/css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Menu ID="mnuTicketMan" Width="100%" runat="server"
Orientation="Horizontal"
StaticEnableDefaultPopOutImage="False"
OnMenuItemClick="mnuTicketMan_MenuItemClick">

<StaticMenuItemStyle CssClass=MenuCell ItemSpacing=0px />
<StaticHoverStyle CssClass=MenuCellHover />
<StaticSelectedStyle CssClass=MenuCellSelected ItemSpacing=0px />
</asp:Menu>

<asp:MultiView ID="mvTicketMan" runat="server" ActiveViewIndex="0">

<%--My Tickets--%>
<asp:View ID="vwMy_Tickets" runat="server" >
<table width="100%" height="100%" cellpadding=0 cellspacing=0>
<tr>
<td class="Canvas">
</td>
</tr>
</table>
</asp:View>
<%--End My Tickets--%>

<%--Watched Tickets--%>
<asp:View ID="vwWatched_Tickets" runat="server">
<table width="100%" height="100%" cellpadding=0 cellspacing=0>
<tr>
<td class="Canvas">
</td>
</tr>
</table>
</asp:View>
<%--End Watched Tickets--%>

<asp:View ID="vwAssigned_Tickets" runat="server">
<table width="100%" height="400px" cellpadding=0 cellspacing=0>
<tr>
<td class="Canvas">
</td>
</tr>
</table>
</asp:View>

</asp:MultiView>
</div>
</form>
</body>
</html>




 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      08-04-2006
Hey John,

I think that you're forgetting that if you want to maintain a variable
between postbacks, you've got to handle it yourself. That is, string
strDBView; only exists for the life of the page. Unless its value is somehow
posted back, the server has no "knowledge" as to what it held previously.

The ASP.NET controls maintain state for themselves but for your global
variable, you need something like:

ViewState["strDVView"] = strDBView;
strDBView = (string)ViewState["strDVView"];

http://msdn.microsoft.com/library/de...statetopic.asp

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]


"John Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am trying to use the menu control for a tabbed menu system but it's
>frustrating the hell out of me. The full code is listed below. The
>trouble that I'm having is that, when the user clicks on a menu item, the
>page will send back the id of the menu that was clicked. But it doesn't do
>that and I can't figure out how to make it work. Looking at the code
>below, the variable "strDBView" is always null. But it's a global variable
>and gets assigned a value upon the menu click. I have tried putting that
>Response.Write line in the !IsPostBack clause with the same results. If I
>place the Response.Write line within the menu click event handler, it does
>writes out a value as expected. So, it's like the value gets set and then,
>upon page load, wiped out.
>
> Any ideas? I have spent 4 days trying to figure this out.
>
> Thanks in advance.
>
> code follows:
> <%@ Page 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">
> string strDBView;
>
> protected void Page_Load(object sender, EventArgs e)
> {
> string strMenuLabel;
>
> // why is strDBView always null? I'm assigning it a value within
> the menu control click evet
> Response.Write("<br />Here: " + strDBView + "</br >");
>
> if (!this.IsPostBack)
> {
> for (int index = 0; index < mvTicketMan.Views.Count; index++)
> {
> strMenuLabel =
> mvTicketMan.Views[index].ID.ToString().Replace("vw", "").Replace("_", "
> ");
> mnuTicketMan.Items.Add(new MenuItem(strMenuLabel,
> index.ToString()));
> }
> mnuTicketMan.Items[0].Selected = true;
> }
> }
>
> protected void mnuTicketMan_MenuItemClick(object sender, MenuEventArgs
> e)
> {
> mvTicketMan.ActiveViewIndex = Int32.Parse(e.Item.Value);
> strDBView =
> mvTicketMan.Views[Int32.Parse(e.Item.Value)].ID.ToString().Replace("vw",
> "").Replace("_", " ");
> // if I show the value here, it does indeed get assigned a proper
> value
> //Response.Write("<br />Here: " + strDBView + "</br >");
> }
> </script>
>
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <title>Untitled Page</title>
> <link href="main.css" type="text/css" rel="stylesheet" />
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
>
> <asp:Menu ID="mnuTicketMan" Width="100%" runat="server"
> Orientation="Horizontal"
> StaticEnableDefaultPopOutImage="False"
> OnMenuItemClick="mnuTicketMan_MenuItemClick">
>
> <StaticMenuItemStyle CssClass=MenuCell ItemSpacing=0px />
> <StaticHoverStyle CssClass=MenuCellHover />
> <StaticSelectedStyle CssClass=MenuCellSelected ItemSpacing=0px />
> </asp:Menu>
>
> <asp:MultiView ID="mvTicketMan" runat="server" ActiveViewIndex="0">
>
> <%--My Tickets--%>
> <asp:View ID="vwMy_Tickets" runat="server" >
> <table width="100%" height="100%" cellpadding=0 cellspacing=0>
> <tr>
> <td class="Canvas">
> </td>
> </tr>
> </table>
> </asp:View>
> <%--End My Tickets--%>
>
> <%--Watched Tickets--%>
> <asp:View ID="vwWatched_Tickets" runat="server">
> <table width="100%" height="100%" cellpadding=0 cellspacing=0>
> <tr>
> <td class="Canvas">
> </td>
> </tr>
> </table>
> </asp:View>
> <%--End Watched Tickets--%>
>
> <asp:View ID="vwAssigned_Tickets" runat="server">
> <table width="100%" height="400px" cellpadding=0 cellspacing=0>
> <tr>
> <td class="Canvas">
> </td>
> </tr>
> </table>
> </asp:View>
>
> </asp:MultiView>
> </div>
> </form>
> </body>
> </html>
>
>
>
>



 
Reply With Quote
 
 
 
 
John Smith
Guest
Posts: n/a
 
      08-04-2006
Ken, you are awesome!! I was overlooking the obvious. That did indeed
solve my problem.

Thank you!
-J



"Ken Cox [Microsoft MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hey John,
>
> I think that you're forgetting that if you want to maintain a variable
> between postbacks, you've got to handle it yourself. That is, string
> strDBView; only exists for the life of the page. Unless its value is

somehow
> posted back, the server has no "knowledge" as to what it held previously.
>
> The ASP.NET controls maintain state for themselves but for your global
> variable, you need something like:
>
> ViewState["strDVView"] = strDBView;
> strDBView = (string)ViewState["strDVView"];
>
>

http://msdn.microsoft.com/library/de...statetopic.asp
>
> Let us know if this helps?
>
> Ken
> Microsoft MVP [ASP.NET]
>
>
> "John Smith" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I am trying to use the menu control for a tabbed menu system but it's
> >frustrating the hell out of me. The full code is listed below. The
> >trouble that I'm having is that, when the user clicks on a menu item, the
> >page will send back the id of the menu that was clicked. But it doesn't

do
> >that and I can't figure out how to make it work. Looking at the code
> >below, the variable "strDBView" is always null. But it's a global

variable
> >and gets assigned a value upon the menu click. I have tried putting that
> >Response.Write line in the !IsPostBack clause with the same results. If

I
> >place the Response.Write line within the menu click event handler, it

does
> >writes out a value as expected. So, it's like the value gets set and

then,
> >upon page load, wiped out.
> >
> > Any ideas? I have spent 4 days trying to figure this out.
> >
> > Thanks in advance.
> >
> > code follows:
> > <%@ Page 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">
> > string strDBView;
> >
> > protected void Page_Load(object sender, EventArgs e)
> > {
> > string strMenuLabel;
> >
> > // why is strDBView always null? I'm assigning it a value

within
> > the menu control click evet
> > Response.Write("<br />Here: " + strDBView + "</br >");
> >
> > if (!this.IsPostBack)
> > {
> > for (int index = 0; index < mvTicketMan.Views.Count; index++)
> > {
> > strMenuLabel =
> > mvTicketMan.Views[index].ID.ToString().Replace("vw", "").Replace("_", "
> > ");
> > mnuTicketMan.Items.Add(new MenuItem(strMenuLabel,
> > index.ToString()));
> > }
> > mnuTicketMan.Items[0].Selected = true;
> > }
> > }
> >
> > protected void mnuTicketMan_MenuItemClick(object sender,

MenuEventArgs
> > e)
> > {
> > mvTicketMan.ActiveViewIndex = Int32.Parse(e.Item.Value);
> > strDBView =
> > mvTicketMan.Views[Int32.Parse(e.Item.Value)].ID.ToString().Replace("vw",
> > "").Replace("_", " ");
> > // if I show the value here, it does indeed get assigned a proper
> > value
> > //Response.Write("<br />Here: " + strDBView + "</br >");
> > }
> > </script>
> >
> > <html xmlns="http://www.w3.org/1999/xhtml" >
> > <head runat="server">
> > <title>Untitled Page</title>
> > <link href="main.css" type="text/css" rel="stylesheet" />
> > </head>
> > <body>
> > <form id="form1" runat="server">
> > <div>
> >
> > <asp:Menu ID="mnuTicketMan" Width="100%" runat="server"
> > Orientation="Horizontal"
> > StaticEnableDefaultPopOutImage="False"
> > OnMenuItemClick="mnuTicketMan_MenuItemClick">
> >
> > <StaticMenuItemStyle CssClass=MenuCell ItemSpacing=0px />
> > <StaticHoverStyle CssClass=MenuCellHover />
> > <StaticSelectedStyle CssClass=MenuCellSelected ItemSpacing=0px />
> > </asp:Menu>
> >
> > <asp:MultiView ID="mvTicketMan" runat="server" ActiveViewIndex="0">
> >
> > <%--My Tickets--%>
> > <asp:View ID="vwMy_Tickets" runat="server" >
> > <table width="100%" height="100%" cellpadding=0

cellspacing=0>
> > <tr>
> > <td class="Canvas">
> > </td>
> > </tr>
> > </table>
> > </asp:View>
> > <%--End My Tickets--%>
> >
> > <%--Watched Tickets--%>
> > <asp:View ID="vwWatched_Tickets" runat="server">
> > <table width="100%" height="100%" cellpadding=0

cellspacing=0>
> > <tr>
> > <td class="Canvas">
> > </td>
> > </tr>
> > </table>
> > </asp:View>
> > <%--End Watched Tickets--%>
> >
> > <asp:View ID="vwAssigned_Tickets" runat="server">
> > <table width="100%" height="400px" cellpadding=0

cellspacing=0>
> > <tr>
> > <td class="Canvas">
> > </td>
> > </tr>
> > </table>
> > </asp:View>
> >
> > </asp:MultiView>
> > </div>
> > </form>
> > </body>
> > </html>
> >
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Menu Control and Sitemap, eliminate the home column on the menu display empire5 ASP .Net 1 01-11-2007 03:30 AM
How do I set selected Menu item in a asp:menu control? goran.strand@gmail.com ASP .Net 0 12-22-2006 08:05 AM
Horizontal Menu Navigation Web Control - Spaces Between Menu Items Philip ASP .Net Web Controls 1 03-21-2006 01:55 PM
Iterating through all the menu/child items in a menu control Bryan ASP .Net 1 03-01-2006 09:38 AM
Adding Access keys to menu items in the Menu control Mike Tavares ASP .Net Web Controls 2 01-05-2006 11:06 AM



Advertisments