ASP.Net LinkButton CSS Adapter
-
08-07-2019 - |
Question
Does anyone know of a CSS Adapter for the LinkButton control for ASP.Net 2?
Update:
We are trying to use CSS Buttons. We are using this approach: http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html For that we need to render the tags which the link button doesn't do.
Possible Solution using Adapter
We created an adapter for the linkbutton. Then changed the RenderContents as follows:
protected override void Render(HtmlTextWriter writer) {
LinkButton linkButton = this.Control;
linkButton.Text = String.Concat("<span>", linkButton.Text, "</span>");
base.Render(writer);
}
This seems to work and requires minimum effort.
Solution 4
Possible Solution using Adapter
We created an adapter for the linkbutton. Then changed the RenderContents as follows:
protected override void Render(HtmlTextWriter writer) {
LinkButton linkButton = this.Control;
linkButton.Text = String.Concat("<span>", linkButton.Text, "</span>");
base.Render(writer);
}
This seems to work and requires minimum effort.
OTHER TIPS
Create a Web Control which would inherit from LinkButton
and only override the RenderContents
method.
It's pretty straightforward and you shouldn't have to duplicate any code or re-implement any features. Of course it's helpful to use .NET Framework source to take a look at the original implementation.
I don't think the output from the LinkButton control could be more CSS friendly.. it is a pure HTML Anchor.
You could easily do this with a user control or custom control to render out
<a...><span>[text]</span></a>
OR - you could use jQuery to find all anchors (maybe with a given class) and insert the span for you.