tags:

views:

96

answers:

2

I have added the following script to my asp.net master page

$(function() {

        $("#someDiv").someMethod(900, {
                chars: /\s/,
                doit: [" ( <a href='#' onclick='window.location.reload(true);' class='truncate_show'>more</a> . . . )", " ( . . . <a href='#' class='truncate_hide'>less</a> )"]
            });


        });

Now when the page loads first time, I see the link 'More'. On clicking 'More' a postback occurs and again the script gets fired. I want to stop executing the script once 'more' is clicked and the page gets reloaded.

A: 

Try changing the default behavior of the link to not actually occur so that you're just getting the onclick event and also maybe after you fire the event try unbinding it using .die() (but you probably won't need that after you stop the link from going off)

Check out Events/die in the jQuery documentation.

Ionise
+1  A: 

If you just want to set that up on the first load of the page, you might consider emitting it through ClientScript.RegisterStartupScript() in Page_Load, within a !IsPostBack conditional.

Ultimately, it might be better if you could keep the show/hide functionality on the client-side completely. It's always difficult drawing the lines between client and server.

If that's not helpful, update your question with a bit more code, and maybe I can give you a more specific answer.

Dave Ward
Thank you Dave, I have mailed you the code.
lols