473,396 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Menu control issue....

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>


Aug 3 '06 #1
2 1649
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" <jo**@hon.comwrote in message
news:OI**************@TK2MSFTNGP02.phx.gbl...
>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>


Aug 4 '06 #2
Ken, you are awesome!! I was overlooking the obvious. That did indeed
solve my problem.

Thank you!
-J

"Ken Cox [Microsoft MVP]" <BA**********@newsgroups.nospamwrote in message
news:uD**************@TK2MSFTNGP06.phx.gbl...
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" <jo**@hon.comwrote in message
news:OI**************@TK2MSFTNGP02.phx.gbl...
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>




Aug 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Reb | last post by:
Hi, I am using drop down menu in my pages. In one of my page,there is a listbox control below the menu. This listbox control is hiding the drop down menu items. How can i make the drop down...
1
by: KB | last post by:
My fellow virtual friends, allow me to ask for your collaboration with this simple yet not-so-trivial matter, My application has a menu which is defined and stored in a database. This menu will...
2
by: fuchsteiner | last post by:
I can't find any support for frames in the asp:menu control. Not the Target frame, but displaying sub-menus across a frame boundary. There are lots of 3rd party Menu tools that do this. I have a...
1
by: Chris Murphy via DotNetMonster.com | last post by:
Hi all, I'm just wondering if any one can help me with this development issue I'm having. I've created a customized treeview control to handle the particular tasks to which I'll be using it. Within...
7
by: tfsmag | last post by:
Has anyone had a problem with putting a menu control into a master page in .net 2.0? I have a problem where if i just drop a menu control on a regular page the menu works fine, the submenus work...
0
by: Jose Walker | last post by:
Hi there! I've been fighting with an issue that by now is driving me crazy. I've developed a ASP.NET 2 web part from which I build dynamically an ASP.NET 2 Menu control, I populate the control...
5
by: AG | last post by:
I realize that the obvious suggestion would be malware, but my definitions are up to date and I have already scanned for it. I have also tried disabling all IE add-ons. I just rebuilt and...
8
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I created a user control that handles certain keystrokes, e.g. Ctrl-C for cut, Ctrl-V for paste, plus other more specialized keystrokes. I want to list these in the menubar like any other menu...
3
by: =?Utf-8?B?VG9tIFc=?= | last post by:
When I mouse over a Menu Control based navigation area the drop-down selection list appears instantaneously. Is there a way to make it less sensitive, so that it delays (even a fraction of a second...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.