简体   繁体   中英

How do I wire up a client Javascript function call when creating a new CheckBox in my codebehind?

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?

这将起作用:

cb.Attributes.Add("onclick", "Javascript:MyClientFunction();");

在后面的代码中,可以使用Attributes.Add("onclick", "Javascript:MyClientFunction();")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM