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

How to set border color from code behind?

4 Answers 1195 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Prasad
Top achievements
Rank 1
Prasad asked on 18 Apr 2012, 03:10 AM
Hi All,

I am looking for a way to set the border color of ComboBox from code behind using PreRender handler of the ComboBox. I have tried the following code and it does not work. Can someone please help me with this?

protected void rcbMyCombo_PreRender(object sender, EventArgs e)
{
        rcbMyCombo.BorderColor = System.Drawing.Color.Red;
        rcbMyCombo.ToolTip = "Error occurred with the data of the control.";
}

Regards,
Prasad

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 18 Apr 2012, 05:58 AM
Hi Prasad,

Please try setting BorderWidth to get the border as follows.

C#:
protected void rcbMyCombo_PreRender(object sender, EventArgs e)
 {
    rcbMyCombo.BorderWidth = Unit.Pixel(1);
    rcbMyCombo.BorderColor = System.Drawing.Color.Red;
    rcbMyCombo.ToolTip = "Error occurred with the data of the control.";
 }

Hope this helps.

Thanks,
Princy.
0
Prasad
Top achievements
Rank 1
answered on 18 Apr 2012, 06:20 AM
Thank you for your help. It worked.

Regards,
Prasad
0
Wayne
Top achievements
Rank 1
answered on 17 Apr 2018, 12:03 AM

Thanks for this. How does one remove a set colour. that is reset back to none.

In my case it is the BackColour I am working with.

 

0
Marin Bratanov
Telerik team
answered on 17 Apr 2018, 11:52 AM
Hello Wayne,

I have just answered your support ticket with the same question and I am pasting the information here for anyone else having the same issue.

As a general rule I would recommend using the CssClass and stylesheets to change the colors: https://docs.telerik.com/devtools/aspnet-ajax/general-information/controlling-visual-appearance/overview.

The BackColor inherits the value of the control parent, so you can reset it to the .Parent.BackColor value. For example:

<asp:Panel runat="server">
    <telerik:RadTextBox runat="server" ID="rtb1"></telerik:RadTextBox>
</asp:Panel>
<asp:Button Text="reset back color" ID="Button1" OnClick="Button1_Click" runat="server" />
protected void Button1_Click(object sender, EventArgs e)
{
    //important: the cast and control hierarchy may differ in your case
    rtb1.BackColor = (rtb1.Parent as System.Web.UI.WebControls.WebControl).BackColor;
}
 
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack) {
        rtb1.BackColor = System.Drawing.Color.Red;
    }
}

 


Regards,
Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
ComboBox
Asked by
Prasad
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Prasad
Top achievements
Rank 1
Wayne
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or