views:

42

answers:

3

I want the programmer to pass a Control to a method, and then I want to add an onclick to it. But control doesn't have an Attributes property. Is there an interface or something deriving from Control that I can use, to add an onclick attribute to it?

Note that I want to add a javascript onclick (clientclick?).

A: 

you can try like...

public void SetClick(TextBox control)
{
    control.Attributes.Add("onclick", "javascript:yourfunction();");
}
Muhammad Akhtar
+1  A: 

D'oh I fixed it now, the solution is to use a WebControl rather than a Control.

SLC
+4  A: 

Check out the System.Web.UI.WebControls.WebControl class - it inherits from System.Web.UI.Control and has an Attributes property.

Anders Fjeldstad