views:

1569

answers:

4

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.

A: 

I don't think the output from the LinkButton control could be more CSS friendly.. it is a pure HTML Anchor.

Quintin Robinson
I need to change the control rendering slightly.
B Z
I don't know it what way, you could just make you're own CSS adapter it shouldn't be difficult for such an easy control.. I can't really imagine in what way you would need to change the anchor rendering, if you explain your goal someone might be able to provide a pure CSS solution.
Quintin Robinson
We are trying to use CSS Buttons. We are using this approach:http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.htmlFor that we need to render the <span> tags which the link button doesn't do.
B Z
A: 

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.

GeekyMonkey
The problem with a user control / custom control is that we only want to override the rendering, not the functionality. WIth a user control / custom control we would have to recreate all the methods/properties and then delegate to the base control
B Z
+1  A: 

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.

Damir Zekić
problem with this approach is it requires to change all references in project for new control, but thanks for suggestion.
B Z
A: 

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.

B Z