Solved

menuitemclick and navigateUrl

Posted on 2008-10-24
8
1,053 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

778 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