1

In my ASP.NET page's code behind I'm creating a checkbox on the fly:

CheckBox cb = new CheckBox();

But I want the new checkbox to call a client function instead of posting back. I would expect to be able to do something like this:

cb.OnClientClick = "Javascript:MyClientFunction();";

But that doesn't exist. How do I wire it up on the fly like that?

2 Answers 2

6

This will work:

cb.Attributes.Add("onclick", "Javascript:MyClientFunction();");
Sign up to request clarification or add additional context in comments.

Comments

1

On code behind you can use Attributes.Add("onclick", "Javascript:MyClientFunction();")

Comments

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.