1

I have this asp.net button

<asp:Button ID="okButton" runat="server" Text="Okay" OnClick="okButton_Click"  />

this is the onButton_Click function

protected void okButton_Click(object sender, EventArgs e){
//bla bla bla
//bla bla bla
}

I have also this javascript function

function callCenterDailyChartYMC() {
//bla bla bla
}

My question

How can I execute that javascript function after finishing executing the button on click function?

Thanks

2

1 Answer 1

1

You can register it as a startup script.

protected void okButton_Click(object sender, EventArgs e){
    ClientScriptManager cs = Page.ClientScript;
    string script = "callCenterDailyChartYMC();";
    cs.RegisterStartupScript(this.GetType(),"NameOfYourScript",script,true);
}

http://msdn.microsoft.com/en-us/library/z9h4dk8y(v=vs.110).aspx

Sign up to request clarification or add additional context in comments.

2 Comments

This is not good way, because you are writing the javascript code inside c# code, I have about 300 code in my javascript function, I hope there is a better(easier) solution
@MarcoDinatsoli it doesn't matter how many lines of code there are, if it is already in a function then all you have to do from your startup script is call your function.

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.