22 October 2009

Creating a readonly Checkbox control

I had to make an ASP.Net checkbox readonly today and found that adding the following :

w.AddAttribute("onClick", string.Format("javascript:{0}.checked = {1};", this.ID, this.Checked.ToString().ToLower()));

to the overridden Render() method of a control that inherits a standard Checkbox control did the trick. The call must be place before the call to the parent classes Render() method.

No comments: