473,606 Members | 2,825 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.dt d">

<script runat="server">
string strDBView;

protected void Page_Load(objec t 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.IsPostBa ck)
{
for (int index = 0; index < mvTicketMan.Vie ws.Count; index++)
{
strMenuLabel =
mvTicketMan.Vie ws[index].ID.ToString(). Replace("vw", "").Replace("_" , " ");
mnuTicketMan.It ems.Add(new MenuItem(strMen uLabel,
index.ToString( )));
}
mnuTicketMan.It ems[0].Selected = true;
}
}

protected void mnuTicketMan_Me nuItemClick(obj ect sender, MenuEventArgs
e)
{
mvTicketMan.Act iveViewIndex = Int32.Parse(e.I tem.Value);
strDBView =
mvTicketMan.Vie ws[Int32.Parse(e.I tem.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>Untitl ed Page</title>
<link href="main.css" type="text/css" rel="stylesheet " />
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Menu ID="mnuTicketMa n" Width="100%" runat="server"
Orientation="Ho rizontal"
StaticEnableDef aultPopOutImage ="False"
OnMenuItemClick ="mnuTicketMan_ MenuItemClick">

<StaticMenuItem Style CssClass=MenuCe ll ItemSpacing=0px />
<StaticHoverSty le CssClass=MenuCe llHover />
<StaticSelected Style CssClass=MenuCe llSelected ItemSpacing=0px />
</asp:Menu>

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

<%--My Tickets--%>
<asp:View ID="vwMy_Ticket s" 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_T ickets" 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 1660
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)ViewSta te["strDVView"];

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

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
"John Smith" <jo**@hon.comwr ote in message
news:OI******** ******@TK2MSFTN GP02.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.Wri te 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.dt d">

<script runat="server">
string strDBView;

protected void Page_Load(objec t 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.IsPostBa ck)
{
for (int index = 0; index < mvTicketMan.Vie ws.Count; index++)
{
strMenuLabel =
mvTicketMan.Vie ws[index].ID.ToString(). Replace("vw", "").Replace("_" , "
");
mnuTicketMan.It ems.Add(new MenuItem(strMen uLabel,
index.ToString( )));
}
mnuTicketMan.It ems[0].Selected = true;
}
}

protected void mnuTicketMan_Me nuItemClick(obj ect sender, MenuEventArgs
e)
{
mvTicketMan.Act iveViewIndex = Int32.Parse(e.I tem.Value);
strDBView =
mvTicketMan.Vie ws[Int32.Parse(e.I tem.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>Untitl ed Page</title>
<link href="main.css" type="text/css" rel="stylesheet " />
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Menu ID="mnuTicketMa n" Width="100%" runat="server"
Orientation="Ho rizontal"
StaticEnableDef aultPopOutImage ="False"
OnMenuItemClick ="mnuTicketMan_ MenuItemClick">

<StaticMenuItem Style CssClass=MenuCe ll ItemSpacing=0px />
<StaticHoverSty le CssClass=MenuCe llHover />
<StaticSelected Style CssClass=MenuCe llSelected ItemSpacing=0px />
</asp:Menu>

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

<%--My Tickets--%>
<asp:View ID="vwMy_Ticket s" 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_T ickets" 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**********@n ewsgroups.nospa mwrote in message
news:uD******** ******@TK2MSFTN GP06.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)ViewSta te["strDVView"];

http://msdn.microsoft.com/library/de...statetopic.asp
>
Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
"John Smith" <jo**@hon.comwr ote in message
news:OI******** ******@TK2MSFTN GP02.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.dt d">

<script runat="server">
string strDBView;

protected void Page_Load(objec t 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.IsPostBa ck)
{
for (int index = 0; index < mvTicketMan.Vie ws.Count; index++)
{
strMenuLabel =
mvTicketMan.Vie ws[index].ID.ToString(). Replace("vw", "").Replace("_" , "
");
mnuTicketMan.It ems.Add(new MenuItem(strMen uLabel,
index.ToString( )));
}
mnuTicketMan.It ems[0].Selected = true;
}
}

protected void mnuTicketMan_Me nuItemClick(obj ect sender,
MenuEventArgs
e)
{
mvTicketMan.Act iveViewIndex = Int32.Parse(e.I tem.Value);
strDBView =
mvTicketMan.Vie ws[Int32.Parse(e.I tem.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>Untitl ed Page</title>
<link href="main.css" type="text/css" rel="stylesheet " />
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Menu ID="mnuTicketMa n" Width="100%" runat="server"
Orientation="Ho rizontal"
StaticEnableDef aultPopOutImage ="False"
OnMenuItemClick ="mnuTicketMan_ MenuItemClick">

<StaticMenuItem Style CssClass=MenuCe ll ItemSpacing=0px />
<StaticHoverSty le CssClass=MenuCe llHover />
<StaticSelected Style CssClass=MenuCe llSelected ItemSpacing=0px />
</asp:Menu>

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

<%--My Tickets--%>
<asp:View ID="vwMy_Ticket s" 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_T ickets" 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
4292
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 menu not to be hidden by the listbox control? I tried to increase the z-index for the menu control. But it did not help.
1
1399
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 be part of any page. Currently I implemented it as a user control which gets the menu from the database and then converts it into the html code, which is then displayed in each page. For some reason I have a feeling that it's not very smart to...
2
1763
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 small horizontal frame that contains the first level of menus and I want second level of menus to display in another frame. I am not finding any references on how to do this on the web. Help!
1
2709
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 the control I'm dynamically creating a context menu and assigning it to the ContextMenu property of the control -- think of this like the default context menu for standard textboxes -- the context menu has a number of menu items that reflect...
7
2419
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 perfect. But if I put that exact same code inside a master page, when i go to view one of the files that use that master page, all of the submenus are out of wack and instead of being hidden, they are at the bottom of the menu, and only go back in...
0
1124
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 dynamically as well... and everything seems to be ok. When running the web application, I get the menu rendered, but no styles are applied to the menu, nor does displays the submenus correctly. When hovering on the menu, displays an emply layer...
5
1606
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 deployed my website (WAP) in ASP.NET 2.0. Everything is working fine except from my development machine with IE6. The master page contains a Menu control bound to a SiteMapDataSource. There is also a row of links (plain links, no menu control) at the...
8
2079
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 items. Once I assign a Shortcut Key to the menu item, that menu sees the event before the control, as one would expect. The question is, then, inside the menu item handler what code do I need to pass on the keystroke to a control? This is slightly...
3
1981
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 would help) before dropping down the menu?
0
8045
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7981
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8467
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8462
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8320
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5994
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3952
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2458
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1315
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.