开发者

Adding a onclick event to a code generated html element via object initializer

I would like to be able to add a click event to a entity generated in the code behind. Currently I'm doing it like this:

 TableRow row = new TableRow();
 row.Attributes.Add("onclick", "clickFunction(this)");

Is 开发者_开发问答there a way to do this using the object initializer? I am doing a lot of control creation/initialization and if it matched the rest of the code it would be nice


No. Unfortunately, the Attributes property only providers a getter. This means you cannot "set" it using an object initializer- only retrieve it. Object initializers only work with properties which provide a setter.

Your current code is probably the best option.


No you cannot. It would be an option to create extension property, but they were not added to c#.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜