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

10 posts, 0 answers
  1. Majid Darab
    Majid Darab avatar
    112 posts
    Member since:
    Dec 2009

    Posted 29 Jun 2010 Link to this post

    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








  2. Dimo
    Admin
    Dimo avatar
    8478 posts

    Posted 01 Jul 2010 Link to this post

    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
  3. Lenny_shp
    Lenny_shp avatar
    343 posts
    Member since:
    Jul 2006

    Posted 06 Jul 2010 Link to this post

    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

  4. Dimo
    Admin
    Dimo avatar
    8478 posts

    Posted 07 Jul 2010 Link to this post

    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
  5. Lenny_shp
    Lenny_shp avatar
    343 posts
    Member since:
    Jul 2006

    Posted 07 Jul 2010 Link to this post

    It stopped working when ReadOnly="true".

    Per Dino's message, setting ReadOnlyStyle.ForeColor worked!
  6. Dimo
    Admin
    Dimo avatar
    8478 posts

    Posted 08 Jul 2010 Link to this post

    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
  7. Infinity
    Infinity avatar
    3 posts
    Member since:
    Jun 2010

    Posted 26 Feb 2011 Link to this post

    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
  8. Lenny_shp
    Lenny_shp avatar
    343 posts
    Member since:
    Jul 2006

    Posted 02 Mar 2011 Link to this post

    Since you are setting ReadOnly to false in the condition you can try using

    refControl.BackColor = Drawing.Color.AntiqueWhite
  9. Infinity
    Infinity avatar
    3 posts
    Member since:
    Jun 2010

    Posted 02 Mar 2011 Link to this post

    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.)
  10. Lenny_shp
    Lenny_shp avatar
    343 posts
    Member since:
    Jul 2006

    Posted 02 Mar 2011 Link to this post

    I am changing ReadOnlyStyle.Forecolor in an AJAX call and it works fine in 2010.2.809.35  IE8.

Back to Top