Solved

menuitemclick and navigateUrl

Posted on 2008-10-24
8
1,073 Views
Last Modified: 2013-11-07
Hi Experts,
the following url is very similar to my problem
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_21815467.html

but in the solution, the expert says "set the navigateUrl before pressing the link.
what does he mean by that and can someone please provide a example or a sample.
I really appreciate it.
Thanks
0
Comment
Question by:niceoneishere
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 12

Expert Comment

by:techExtreme
ID: 22799097
Hello,
What the expert meant was that instead of coding in the event 'Menu1_MenuItemClick'  which url the link should make user go ,
you should code it ahead of that event i.e. say for example
during Page_Load() event, if your menu has say 3 links, you can
code it in like this:

Page_Load()if not ispostback'Set your menu item's navigateurl property in here.end ifEnd Sub
By doing like this, the menu's items will always know where to go and
on First Click it will send user to the appropriate url and for this,
no need to code the Menu_MenuItemClick() event.

I guess its very simple and you won't have trouble adding code to page_load()
Let me know in case of any problems

Enjoy Coding!
0
 
LVL 3

Expert Comment

by:rundkaas
ID: 22799228
Well to help you it would be best if you could post how you are creating the menu today, then we could indentify how best to solve the issue.
0
 
LVL 1

Author Comment

by:niceoneishere
ID: 22799390
Hi Sir,
well my menu is in user control which is in a library project. like below
menu.ascx.cs
public event MenuEventHandler menuItemclick;
protected void menuclick_setNavLinks(object sender, MenuEventArgs e)
 {
            if (menuItemclick != null)
            {
                menuItemclick(this, e);}
}
and then in my aspx.cs
protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            menuUCID.menuItemclick += new MenuEventHandler(menuUC_menuItemclick);

        }
protected void menuUC_menuItemclick(object sender, MenuEventArgs e)
        {
            switch (e.Item.Value)
            {
                case "item1":
                    e.Item.NavigateUrl = "Customer.aspx?id=" + Id;
                     // here is the problem which was coming before.
                    // i followed rundkass solution in the link i posted in this post and did a redirect
                   // just wondering how to do this in the second option Rundkass mentioned.
                  // sorry didnt mean to question any one. I apologize if i did
                    return;
             
            }

        }
Thanks and i appreciate it
0
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 
LVL 3

Expert Comment

by:rundkaas
ID: 22799426
Hi, could you post the markup part as well, from the user control.
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22802182
Hello,
Try setting up navigationurl property in the Page_Load() event of your Menu user control?
0
 
LVL 1

Author Comment

by:niceoneishere
ID: 22803372
the user control code
menu.acsx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="menu.ascx.cs" Inherits="UserControls_menu" %>
<asp:Menu ID="Menu1" runat=server DynamicHorizontalOffset="2"
Orientation="Horizontal" StaticSubMenuIndent="10px"  
OnMenuItemClick="menuclick_setNavLinks" BackColor="#FFFBD6"
Font-Names="Verdana" Font-Size="0.8em" ForeColor="#990000">
     <Items>
        <asp:MenuItem Text="Men Shoes" Value="1"></asp:MenuItem>
        <asp:MenuItem Text="Women Shoes" Value="2"></asp:MenuItem>
            </Items>
    <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
    <DynamicHoverStyle BackColor="#990000" ForeColor="White" />
    <DynamicMenuStyle BackColor="#FFFBD6" />
    <StaticSelectedStyle BackColor="#FFCC66" />
    <DynamicSelectedStyle BackColor="#FFCC66" />
    <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
    <StaticHoverStyle BackColor="#990000" ForeColor="White" />
       
</asp:Menu>

and menu.acsx.cs
public partial class UserControls_menu : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public event MenuEventHandler menuItemclick;


    protected void menuclick_setNavLinks(object sender, MenuEventArgs e)
    {
        if (menuItemclick != null)
        {
            menuItemclick(this, e);
        }
    }
}

Thanks I appreciate it
0
 
LVL 3

Accepted Solution

by:
rundkaas earned 500 total points
ID: 22804884
Hi again,
According to the markup code you have posted then you are creating the menu items declerativly,
then why don't you also set the navinateUrl at the same time.

If you need some more advanced logic to what the navinate url will point to, then I would recomend that you leave the items blank in markup, and rather set them yourself in code in the Page_Load method.
Like this:
protected void Page_Load(object sender, EventArgs e)
    {
        Menu1.Items.Add(new MenuItem("Mens Shoes", "1", null, "Customer.aspx?id=" + Id));
    }

<Items>
                <asp:MenuItem Text="Men Shoes" Value="1" NavigateUrl="someOtherPage.aspx"></asp:MenuItem>
                <asp:MenuItem Text="Women Shoes" Value="2"></asp:MenuItem>
            </Items>

Open in new window

0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22804975
I already asked him to try setting navigateurl in Page_Load() event :)
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question