Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding a confirm prompt to asp:menuitem 2

Status
Not open for further replies.

NuJoizey

MIS
Aug 16, 2006
450
US
This code example comes directly from MSDN at
My question is, say, I wanted to add some sort of confirmation prompt, like a javascript confirm() dialog for when the user selects the "Drama" option.

In other words, I before the page writes "you chose Drama" I want to challenge the user with "are you sure you want to choose drama?".

Can this be done?

Code:
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<script runat="server">

  Sub NavigationMenu_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs)

    ' Display the text of the menu item selected by the user.
    Message.Text = "You selected " & _
      e.Item.Text & "."

  End Sub

</script>

<html  >
  <head id="Head1" runat="server">
    <title>Menu MenuItemClick Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>Menu MenuItemClick Example</h3>

      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        onmenuitemclick="NavigationMenu_MenuItemClick" 
        runat="server">

        <items>
          <asp:menuitem text="Home"
            tooltip="Home">
            <asp:menuitem text="Music"
              tooltip="Music">
              <asp:menuitem text="Classical"
                tooltip="Classical"/>
              <asp:menuitem text="Rock"
                tooltip="Rock"/>
              <asp:menuitem text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem text="Movies"
              tooltip="Movies">
              <asp:menuitem text="Action" 
                tooltip="Action"/>
              <asp:menuitem text="Drama" 
                tooltip="Drama"/>
              <asp:menuitem text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>

      </asp:menu>

      <hr/>

      <asp:label id="Message" 
        runat="server"/>

    </form>
  </body>
</html>
 
I would build the menu manually using repeaters and link buttons. then assign javascript to to the onclientclick property.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
yes, and another way would be to use an AJAX toolkit modalpopupextender control to substitute for the javascript confirm box, and fire the server side code based on a linkbutton onClick event.

But I can't believe that there isn't some way to implement client side javascript on a menuItem submenu. It seems like this would be something that would need to be done pretty often.
 
I've never worked with the menucontol, but couldn't you iterate through the items in the menu in the code behind, and add an attribute to it?
 
But I can't believe that there isn't some way to implement client side javascript on a menuItem submenu. It seems like this would be something that would need to be done pretty often.
I can :) anytime I want to customize a webcontrol I feel like I'm bending the framework to do so. this is why I try to use the "basic" controls as much as possible.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Have you seen some of the HTML that the Menu control creates?! I'd avoid it at all costs.

If you know the menu items at design time, a simple <ul> list should suffice. If not, just create each <li> via a repeater control. That's a much neater, less bloated and faster method.

Mark,

[URL unfurl="true"]http://lessthandot.com[/url] - Experts, Information, Ideas & Knowledge
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Website Design
[URL unfurl="true"]http://aspnetlibrary.com[/url] - An online resource for professional ASP.NET developers
 
anytime I want to customize a webcontrol I feel like I'm bending the framework to do so

yeah, I distinctly remember us having had that conversation before. I think you might have even quoted me!

couldn't you iterate through the items in the menu in the code behind, and add an attribute to it

you would think. I tried that, but I couldn't see how to make this happen.

the following posting might give some promise:

 
c8msm says:

Have you seen some of the HTML that the Menu control creates?!

as long as it renders properly, why does this matter - i assume problem with this is that the messy html causes problems rendering across different browsers?

I am only targeting IE 7 and FF 2.0 for the moment, since the app is only being delivered in house in a controlled browser environment (thank goodness) I ahven't had trouble wiht the HTML in those two browsers.
 
as long as it renders properly, why does this matter - i assume problem with this is that the messy html causes problems rendering across different browsers?
but it's not, that's why you have so much friction trying to customize this.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
it renders OK visually, the problem is in that there is no obvious way to access the HTML elements that it does render - I guess that is more of a critique of .NET framework than anything else. If that's what c8msm meant by the remark then yes, I share her outrage.
 
NuJoizey said:
as long as it renders properly, why does this matter
There are 3 very good reasons I can think of:

1. The bloated code will mean your page takes longer to load
2. The styling of the menu becomes slightly more difficult due to the HTML structure
3. The HTML elements it generates are semantically incorrect as they do not correctly describe what the content is

Mark,

[URL unfurl="true"]http://lessthandot.com[/url] - Experts, Information, Ideas & Knowledge
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Website Design
[URL unfurl="true"]http://aspnetlibrary.com[/url] - An online resource for professional ASP.NET developers
 
well said mark

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
oops! sorry mark!

- stephanie

(aka steve, aka NuJoizey)
 
FYI: the technique shared at


seems to work, sloppy HTML not withstanding. My perception of asp.net 2.0 is that on the whole it does not do a good job of creating clean HTML. I've heard this criticism of bloated code and poor semantics in several places.

At this phase in my .net dev career, honestly i'm just happy i can get the $#%! thing to even work.
 
for anyone else that might be researching this issue, I found is another string of posts that deal with it.


I regret to say that I came to the same conclusion as did the user "whatispunk" who raises essentially the same questions.

I too got fed up, decided it was too much trouble to get this to work as i thought it should, and ended up inventing another solution using the AJAX modalPopupExtender.

i will edit this thread if a solution is found.
 
NuJoizey said:
i will edit this thread if a solution is found.
The best and easiest solution has already been given in the first reply by Jason:
jmeckley said:
I would build the menu manually using repeaters and link buttons. then assign javascript to to the onclientclick property.

Mark,

[URL unfurl="true"]http://lessthandot.com[/url] - Experts, Information, Ideas & Knowledge
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Website Design
[URL unfurl="true"]http://aspnetlibrary.com[/url] - An online resource for professional ASP.NET developers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top