This is a migrated thread and some comments may be shown as answers.

Issue with CSS Friendly Control Adapters LinkButtonAdapter

2 Answers 44 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 10 Mar 2009, 03:30 AM
Hi

I am using the latest CSS Friendly Control Adapters LinkButtonAdapter which can be found here http://cssfriendly.codeplex.com/SourceControl/ListDownloadableCommits.aspx. I am ONLY using the LinkButtonAdapter.

I need it to put a <span>TEXT</span> in between the link text.

Now It has stuffed up the paging of the gridview. The non active page links work, but the active page, ie page 1, does not render. Is anyone familiar with overriding controls and can help me here?

To get away with it, this is what I have done. Anyone have a better idea?

if (String.IsNullOrEmpty(linkButton.Text)) 
                    { 
                        base.RenderContents(writer); 
                    } 
                    else 
                    { 
                        writer.WriteBeginTag("a"); 
                        writer.WriteAttribute("id", linkButton.ClientID); 
                        writer.WriteAttribute("title", linkButton.ToolTip); 
                        writer.WriteAttribute("class", className); 
                        writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(linkButton, "")); 
                        writer.Write(HtmlTextWriter.TagRightChar); 
                        writer.WriteBeginTag("span"); 
                        writer.WriteAttribute("class""AspNet-LinkButton-Text"); 
                        writer.Write(HtmlTextWriter.TagRightChar); 
                        writer.Write(linkButton.Text); 
                        writer.WriteEndTag("span"); 
                        writer.WriteEndTag("a"); Page.ClientScript.RegisterForEventValidation(linkButton.UniqueID); 
                    } 

2 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 11 Mar 2009, 02:16 PM
Hello Michael,

You may  try overriding the RenderContents similar to the following:
public class LinkButtonAdapter : WebControlAdapter  
    {  
        public LinkButton CurrentControl  
        {  
            get   
            {  
                return ((LinkButton) Control);  
            }  
        }  
 
        protected override void RenderContents(HtmlTextWriter writer)  
        {  
            if (string.IsNullOrEmpty(CurrentControl.Text))  
            {  
                //LinkButton has a nested controls inside  
                if (CurrentControl.HasControls() && CurrentControl.Controls[0] is LiteralControl)  
                {  
                    writer.RenderBeginTag(HtmlTextWriterTag.Span);  
                    CurrentControl.Controls[0].RenderControl(writer);  
                    writer.RenderEndTag();  
                    CurrentControl.Controls.RemoveAt(0);  
                }  
            }  
            else 
            {  
                writer.RenderBeginTag(HtmlTextWriterTag.Span);  
                writer.Write(CurrentControl.Text);  
                CurrentControl.Text = string.Empty;  
                writer.RenderEndTag();  
            }  
 
            base.RenderContents(writer);  
        }  
    } 

Please give it a try and let us know about the results.

Greetings,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Michael
Top achievements
Rank 1
answered on 11 Mar 2009, 10:31 PM
Works excellent thanks heaps!
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Michael
Top achievements
Rank 1
Share this question
or