Multiline text on RadButton

7 posts, 0 answers
  1. Jaakko
    Jaakko avatar
    4 posts
    Member since:
    Aug 2013

    Posted 15 Aug 2013 Link to this post

    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

  2. Jaakko
    Jaakko avatar
    4 posts
    Member since:
    Aug 2013

    Posted 15 Aug 2013 Link to this post

    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 ?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Aug 2013 Link to this post

    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.
  5. Jaakko
    Jaakko avatar
    4 posts
    Member since:
    Aug 2013

    Posted 16 Aug 2013 Link to this post

    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;
    }

  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Aug 2013 Link to this post

    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.
  7. Martin
    Martin avatar
    3 posts
    Member since:
    Aug 2013

    Posted 19 Aug 2013 Link to this post

    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).
  8. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 19 Aug 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017