Solved

menuitemclick and navigateUrl

Posted on 2008-10-24
8
1,039 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Hi, could you post the markup part as well, from the user control.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 12

Expert Comment

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

Author Comment

by:niceoneishere
Comment Utility
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
Comment Utility
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
Comment Utility
I already asked him to try setting navigateurl in Page_Load() event :)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

20 Experts available now in Live!

Get 1:1 Help Now