0

I have a asp server button for which I have onClick for code behind code execution and onClientClick to execute javascript function.

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
        style="z-index: 1; left: 648px; top: 202px; position: absolute" 
        Text="Show route" OnClientClick="droute(); return false" />

I am unable to determine whether onClick event is generated first or onClientClick is executed first or do they run parallel? I want onClick event to be generated first and then onClientClick because the latter needs value retrieved from the former.

1 Answer 1

2

If you want to control the order of execution, you can just make one javascript function that calls your two other functions in the desired order and hook that one function up to onclick and not leave anything up to ASP.NET?

<asp:Button ID="Button1" runat="server" onclick="thisClick()" 
    style="z-index: 1; left: 648px; top: 202px; position: absolute" 
    Text="Show route"/>

function thisClick() {
    Button1_Click.apply(this, arguments);
    droute.apply(this, arguments);
    return false;
}
Sign up to request clarification or add additional context in comments.

4 Comments

I get an error: 'ASP.welcome_aspx' does not contain a definition for 'thisClick' and no extension method 'thisClick' accepting a first argument of type 'ASP.welcome_aspx' could be found (are you missing a using directive or an assembly reference?)
@Cdeez - There was a typo in the HTML in my original post which I have corrected.
that wasn't the issue. Is it onclick ? Because onclick looks for the function in code behind right? I changed to onclientclick and no error. but in firebug I have placed breakpoints and the code inside thisClick dint execute
Update: Only assigning thisClick() to onClientClick works. And breakpoints show that in function thisClick(), only Button1_Click.apply(this, arguments); line is executed and then page reloads. The next line droute() isn't executed

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.