Solved

menuitemclick and navigateUrl

Posted on 2008-10-24
8
1,047 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
  • 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
 
LVL 3

Expert Comment

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

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with Filesystemobject or .NET version 3 31
Error on link 14 36
C#  Radio button search for Date not DateTime 4 32
Message not shown 5 27
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 …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now