Ashish Rathore Ashish Rathore - 1 month ago 13
Javascript Question

How to add client side event on asp:menu item click

I am using

<asp:Menu>
control in my web site and populated it from my Sql Server database table using XML data source.
Now i want to add a client side event on menu item click.
When a user clicks any menu item i need to show a please wait dialog window until the page got complete refreshed.
For that i need to run my java script function on client click.
So can any one tell me how to add a client side click event on menu item click.

Answer

Problem is solved by adding css classes

<DynamicMenuStyle CssClass="primaryDynamicMenu" />
<StaticMenuStyle CssClass="primaryStaticMenu"/>

And then add this jquery function for main-menu items:

$(function() {
    $(".primaryStaticMenu a").each(function(index) {
        $(this).click(function() {
            alert($(this).attr("href"));
        });
    });
});

For sub-menu items:

$(function() {
    $(".primaryDynamicMenu a").each(function(index) {
        $(this).click(function() {
            alert($(this).attr("href"));
        });
    });
});