c# - Add attributes to a control class -
i wanna know if possible add attribute control in c#.
i have method receive object in parameter :
public void createtooltip(object controltoadd = null) { var mydiv = new htmlgenericcontrol("div"); mydiv.attributes.add("width", "100%"); mydiv.attributes.add("onmouseover", "showhint('" + this.gettype() + "','test');"); mydiv.attributes.add("onmouseout", "hidehint();"); if (controltoadd == null) { list<control> listcc = new list<control>(); (int = 0; < this.controls.count; i++) { control cc = this.controls[i]; string test = cc.gettype().tostring(); listcc.add(cc); } this.controls.clear(); (int = 0; < listcc.count; i++) { control cc = listcc[i]; mydiv.controls.add(cc); } } else { control cc = (control)controltoadd; //don't know here... } this.controls.add(mydiv); } if object null, create htmlgenericcontrol("div") , add attributes want. problem when object not null, convert control, , property attributes not available. use control because never know type of object received in parameter.
you need cast webcontrol or htmlgenericcontrol believe. control not contain property attributes. can test object pass using is.
if (control webcontrol) { var webcontrol = (webcontrol)control; } or if prefer use as:
var webcontrol = control webcontrol; if (webcontrol != null) { // code }
Comments
Post a Comment