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

Changing RadTextBox ForeColor In CodeBehind Works Only For One Time And Fore More Problems Appear

9 Answers 420 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Majid Darab
Top achievements
Rank 1
Majid Darab asked on 29 Jun 2010, 09:33 PM
hi dear telerik team :
my aspx code is like this :
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"
    <title></title
     
     
    <link href="App_Themes/Input/Office2007ByMe/Input.Office2007ByMe.css" rel="stylesheet" 
        type="text/css" /> 
     
</head> 
<body> 
    <form id="form1" runat="server"
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
    </telerik:RadScriptManager> 
    <div> 
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="Button1"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="RadTextBox1" /> 
                        <telerik:AjaxUpdatedControl ControlID="Button1" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
                <telerik:AjaxSetting AjaxControlID="Button2"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="RadTextBox1" /> 
                        <telerik:AjaxUpdatedControl ControlID="Button2" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
                <telerik:AjaxSetting AjaxControlID="Button3"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="RadTextBox1" /> 
                        <telerik:AjaxUpdatedControl ControlID="Button3" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
        <telerik:RadTextBox ID="RadTextBox1" runat="server" EnableEmbeddedSkins="False"  
            Width="125px" Skin="Office2007ByMe"
        </telerik:RadTextBox> 
        <br /> 
        <br /> 
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> 
        <asp:Button ID="Button2" runat="server"  Text="Button"  
            onclick="Button2_Click" /> 
        <asp:Button ID="Button3" runat="server"  Text="Button"  
            onclick="Button3_Click" /> 
    </div> 
    </form> 
</body> 
</html> 

and codebehind :
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
 
namespace ChatRoomByMajid 
    public partial class WebForm2 : System.Web.UI.Page 
    { 
        protected void Page_Load(object sender, EventArgs e) 
        { 
             
        } 
 
 
        protected void Button1_Click(object sender, EventArgs e) 
        { 
            RadTextBox1.ForeColor = System.Drawing.Color.Red; 
             
        } 
 
        protected void Button2_Click(object sender, EventArgs e) 
        { 
            RadTextBox1.ForeColor = System.Drawing.Color.Yellow; 
        } 
 
        protected void Button3_Click(object sender, EventArgs e) 
        { 
            RadTextBox1.ForeColor = System.Drawing.Color.Blue; 
        } 
    } 
 


when i click those buttons so the forecolor changes , but when the radtextbox gets focus for entering data so the previous color is shown!

how can i fix this problem ?
(i made the simple upper code for understanding)

best regards








9 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 01 Jul 2010, 01:16 PM
Hi Majid,

Please use

RadTextBox1.EnabledStyle.ForeColor = System.Drawing.Color.Red;
RadTextBox1.HoveredStyle.ForeColor = System.Drawing.Color.Red;
RadTextBox1.FocusedStyle.ForeColor = System.Drawing.Color.Red;

The single ForeColor property can be used only on initial page load.

Regards,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Lenny_shp
Top achievements
Rank 2
answered on 06 Jul 2010, 08:58 PM
Same issue here (only works the first time), I set all 3 in TextChanged event with 2009.3.1503.35 and is still not working for me in IE8.

Skin="Simple" ReadOnly="true"

Text shows, just the color isn't changing between black and red.

            txtEntityDesc.EnabledStyle.ForeColor = Drawing.Color.Red
            txtEntityDesc.HoveredStyle.ForeColor = Drawing.Color.Red
            txtEntityDesc.FocusedStyle.ForeColor = Drawing.Color.Red

0
Dimo
Telerik team
answered on 07 Jul 2010, 07:27 AM
Hi Lenny,

Here is a simple test page, which works as expected on my side. Please compare with your implementation.


<%@ Page Language="C#" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<script runat="server">
 
    protected void RadTextBox1_TextChanged(object sender, EventArgs e)
    {
        (sender as RadTextBox).EnabledStyle.ForeColor = System.Drawing.Color.Red;
        (sender as RadTextBox).HoveredStyle.ForeColor = System.Drawing.Color.Red;
        (sender as RadTextBox).FocusedStyle.ForeColor = System.Drawing.Color.Red;
    }
     
</script>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
<head runat="server">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>RadControls</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
 
<telerik:RadTextBox ID="RadTextBox1" runat="server" OnTextChanged="RadTextBox1_TextChanged" Text="black text" />
 
<asp:Button ID="Button1" runat="server" Text="PostBack" />
 
</form>
</body>
</html>


Greetings,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Lenny_shp
Top achievements
Rank 2
answered on 07 Jul 2010, 07:21 PM
It stopped working when ReadOnly="true".

Per Dino's message, setting ReadOnlyStyle.ForeColor worked!
0
Dimo
Telerik team
answered on 08 Jul 2010, 07:41 AM
Well, if you are using ReadOnly="true", you need to set ReadOnlyStyle.ForeColor.

Regards,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Infinity
Top achievements
Rank 1
answered on 27 Feb 2011, 12:47 AM
I'm having the same issue with the RadTextbox's ReadOnlyStyle.ForeColor property, but I am also using Ajax.

In my project, I have a checkbox:

<asp:CheckBox ID="chkIncludeForm" AutoPostBack="true" runat="server" Text="Include Form with this filing." />

When clicked, the remaining RadTextbox controls on the panel are made ReadOnly or Writeable based on the value of the checkbox:

Private Sub chkIncludeForm_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkIncludeForm.CheckedChanged
  
     For Each pageControl As Control In pnlForm.Controls
  
          If TypeOf pageControl Is RadTextBox Then
               Dim refControl As RadTextBox = CType(pageControl, RadTextBox)
  
               If chkIncludeForm.Checked Then
                    refControl.ReadOnlyStyle.BackColor = Drawing.Color.AntiqueWhite
                    refControl.ReadOnly = False
               Else
                    refControl.ReadOnlyStyle.BackColor = Drawing.Color.DarkGray
                    refControl.ReadOnly = True
               End If
          End If
     Next
End Sub

The page is Ajaxified with the RadAjaxManager, like so:

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="chkIncludeForm">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="pnlForm" LoadingPanelID="ldpForm" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

The click event of the checkbox fires properly on the server and each RadTexbox is disabled accordingly, but the ReadOnlyStyle.BackColor preoprty is not taking effect.  Do I need to call the updateCssClass method on the client-side for each control for the change to take effect or is there something else that needs to be done?

Thanks!

Steve
0
Lenny_shp
Top achievements
Rank 2
answered on 02 Mar 2011, 03:52 PM
Since you are setting ReadOnly to false in the condition you can try using

refControl.BackColor = Drawing.Color.AntiqueWhite
0
Infinity
Top achievements
Rank 1
answered on 02 Mar 2011, 03:58 PM
Thanks, Lenny...  But it's the ReadOnlyStyle.BackColor that's not working properly when when ReadOnly = True...  The standard control BackColor is working properly.  (You are correct that the first part of that If Statement isn't needed.)
0
Lenny_shp
Top achievements
Rank 2
answered on 02 Mar 2011, 04:28 PM
I am changing ReadOnlyStyle.Forecolor in an AJAX call and it works fine in 2010.2.809.35  IE8.

Tags
Ajax
Asked by
Majid Darab
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Lenny_shp
Top achievements
Rank 2
Infinity
Top achievements
Rank 1
Share this question
or