1

javascript code

function logoutPop() {
       var a = confirm("are you sure !");
       if (a = true)
           return true;
       else return false;
    }

aspx file

    protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
        {
            string selectedItem = e.Item.Value;
            if (selectedItem == "logout")
            {
// here i want to call javascript function logoutPop() and check return value. if true want to redirect login page else nothing.

Is there any way to do this . I tried scriptmanager but not success . Please help . Thank you.

2

3 Answers 3

1

Use ClientScriptManager.RegisterClientScriptBlock

See the following link. http://msdn.microsoft.com/en-us/library/btf44dc9.aspx

Regards,

0

As far as i know you can't do that.You can run javascript code before page load or after the server side code has been executed.You can't make javascript work in between c# code execution and then return back to c#.

0

This is not possible with ASP.NET Menu Control to register a javascript method on click events.

I hope i understood your problem right! You want a Confirm box on one of the Menu Items which needs to be displayed on the Client Side(Browser) without a postback.

This can only be achieved by playing around with the DOM using jQuery after the document gets rendered.

jQuery Code:

$(document).ready(function () {
        $('#MainContent_mTest a').each(function () {
            var anchorHtml = $(this).html();
            if (anchorHtml == 'logout') {
                var clickEvent = this.onclick;
                this.onclick = "";
                $(this).bind('click', function (ev) {
                    if (confirm("Are you sure !")) {
                        clickEvent();
                    }
                    else {
                        return false;
                    }
                });
            }
        });

I hope this solves your problem...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.