Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

menuitemclick and navigateUrl

Posted on 2008-10-24
8
Medium Priority
?
1,078 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
Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

 
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 1500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

715 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