tags:

views:

40

answers:

2

I have a window.onbeforeunload event that I wish to disable when I am clicking on a specific hyperlink.

I am using the following JQuery:

    $(function() {
        $("a#<%= lockUnlock.ClientID %>").click(function() { 
            window.onbeforeunload = null; });
    });

But when I click on other links the event doesn't fire.

Is there any way around this?

EDIT (more info):

I am using asp.net

lockUnlock is a link button which is on an update panel. The link button is pressed, after the partial page back the window.onbeforeunload doesn't work anymore.

A: 

Not sure if I can help, but are you sure that the <%= lockUnlock.ClientID %> is coming out as non null? Obviously, if it is evaluating to an empty string, all your anchors will end up getting bound to this click handler.

Also, are you auto-generating this javascript? If not, how is the <%= lockUnlock.ClientID %> getting replaced with the actual ID? I can't say I use ASP or ASP.NET as much as PHP, so I'm a little rusty on when this replacement would occur.

Hopefully it'll all get figured out!

Mike
You may be onto something. I've just copied this a simple html form and it works fine.
John Nolan
A: 

ClientID will only be populated on Page.PreRender event. If you're doing this on Page.Load, then ClientID will have empty value (or null). That's probably not what you're expecting for the jQuery selector.

Adrian Godong