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

Multiline text on RadButton

6 Answers 194 Views
Button
This is a migrated thread and some comments may be shown as answers.
Jaakko
Top achievements
Rank 1
Jaakko asked on 15 Aug 2013, 06:39 AM
Hello,

I have tried to set the text property in code-behind to "\n", Environment.Newline, Server.HtmlDecode("Carriage
return");
and "<br />" but nothing has created multiline text on RadButton. My searching for answers has also found the aspx
templating : 
<
ContentTemplate>
        <span>RadButton Content</span><br />
<span>RadButton Content2</span>
 </ContentTemplate>
but even this is not giving me multiple lines.
Is there any other workaround for this ?

Martin

6 Answers, 1 is accepted

Sort by
0
Jaakko
Top achievements
Rank 1
answered on 15 Aug 2013, 09:48 AM
For me it is absolutely important to set the text in code behind by accesssing a property
and therefore I believe that I can't use <ContentTemplate>.

What should I do ?
0
Shinu
Top achievements
Rank 1
answered on 16 Aug 2013, 03:30 AM
Hi Jaakko,

Please try the following code snippet which set the multiline text for RadButton in code behind.

ASPX:
<telerik:RadButton runat="server" ID="RadButton1" Width="70px" Height="65px" />

C#:
protected void Page_Load(object sender, EventArgs e)
{
    RadButton1.Text = "This is \n a new line";
}

Thanks,
Shinu.
0
Jaakko
Top achievements
Rank 1
answered on 16 Aug 2013, 06:06 AM
Yes I have tried that:

ASPX
<telerik:RadButton ID="RadButton1" runat="server" Text="RadButton" Image-ImageUrl="~/Images/button.png" Width="300" Height="90">
   </telerik:RadButton>

C#
RadButton1.Text = "Test \n Test2";
RadButton1.Image.IsBackgroundImage = true;

Attached is the resulting button, without multiple lines.
This bothers me, I was able to do multiline with Templating :
<ContentTemplate>
            <div class = "buttonStyle">
                <telerik:RadBinaryImage ID="RadBinaryImage1" runat="server" ImageUrl="~/Images/compatible_firefox.gif" />
            </div>
            <div class = "buttonStyle">
                <span class="btnText">
                    Test1</span>
                <span class="btnText">
                    Test2</span>
            </div>
        </ContentTemplate>

CSS:
.btnText {
     display: block;
     line-height: 20px;
     text-align:left;
     color: #fff;
     font-size:larger;
     
}
.buttonStyle
{
    float:left;
    margin: 10px 0px 0px 10px;
}

0
Shinu
Top achievements
Rank 1
answered on 16 Aug 2013, 08:49 AM
Hi Jaakko,

I tried the following approach to solve the issue.

C#:
protected void Page_Load(object sender, EventArgs e)
{
    System.Web.UI.HtmlControls.HtmlGenericControl text1 = (System.Web.UI.HtmlControls.HtmlGenericControl)RadButton1.FindControl("span1");
    text1.InnerText = "test1";
    System.Web.UI.HtmlControls.HtmlGenericControl text2 = (System.Web.UI.HtmlControls.HtmlGenericControl)RadButton1.FindControl("span2");
    text2.InnerText = "test2";
}

Hope this will help you.

Thanks,
Shinu.
0
Martin
Top achievements
Rank 1
answered on 19 Aug 2013, 07:02 AM
Thank You Shinu.

I will try to use the FindControl approach.
This needs more code and is not so elegant as would have been
inserting just some formatting in the text string.

Martin (Now by my 'own' account).
0
Danail Vasilev
Telerik team
answered on 19 Aug 2013, 01:07 PM
Hi all,

You may also find useful this and this forum discussions that shed more light on the matter.

Regards,
Danail Vasilev
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Button
Asked by
Jaakko
Top achievements
Rank 1
Answers by
Jaakko
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Martin
Top achievements
Rank 1
Danail Vasilev
Telerik team
Share this question
or