I'm refactoring some of our old code, I'm replacing our old status images as Font Awesome Icons.
We have a method that creates an image and returns it, for dynamically adding controls to a page.
Old Code
return new Image {
ImageUrl = SomeConstURL,
ToolTip = tooltip
};
New Code
return new HtmlGenericControl
{
InnerHtml = IconFactory("fa-circle", UnacceptableIconClass, "fa-2x"),
Attributes = { Keys = tooltip}
};
When I use the above new code I get the error:
Error 638 Property or indexer 'Keys' cannot be assigned to -- it is read only
It's a straight forward error, it's read only, I can't assign it that way.
I've done it in the past with:
someIcon.Attributes["title"] = "My tooltip text";
However when I try and do the same inside the initializer:
new HtmlGenericControl
Attributes["title"] = "My tooltip text"
}
I get the error:
Invalid initializer member delcarator
I just have no idea how to do this in the initializer.
I've looked at the docs for HtmlGenericControl
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…