Changing FocusedStyle in Page_Load?

3 posts, 0 answers
  1. Eddie
    Eddie avatar
    66 posts
    Member since:
    May 2008

    Posted 30 Jul 2008 Link to this post

    I need to set the style of RadNumericTextBox and RadMaskedTextBox controls on my form.  When I load the page I go through all of the controls and set the styles based on the type of control.  This is in my Page_Load method.  It works fine for all standard asp.net controls, but I can't get it to do anything to the styles for the Telerik controls.  I've tried using the onblur and onfocus events.  Then I tried using the ClientEvents-OnBlur and OnFocus (setting "this.className='bla'", for example) but that didn't work either.  So then I tried setting the FocusedStyle.BorderWidth and BorderColor, but that had no affect on the controls either.  I can step through in debug and see that these properties ARE set, but the controls don't change at all on focus...  Here's the code I'm using to do this:
    foreach (Control ctl in pnlMain.Controls)  
    {  
        if(ctl.GetType() == typeof(TextBox))  
        {  
            ((WebControl)ctl).Attributes.Add("onfocus""this.className='textBoxActive'");  
            ((WebControl)ctl).Attributes.Add("onblur""this.className='textBox'");  
        }  
        else if(ctl.GetType() == typeof(RadNumericTextBox))  
        {  
            ((RadNumericTextBox)ctl).FocusedStyle.BorderWidth = 2;  
            ((RadNumericTextBox) ctl).FocusedStyle.BorderColor = Color.DarkSlateBlue;  
        }  
        else if(ctl.GetType() == typeof(RadMaskedTextBox))  
        {  
            ((RadMaskedTextBox)ctl).FocusedStyle.BorderWidth = 2;  
            ((RadMaskedTextBox)ctl).FocusedStyle.BorderColor = Color.DarkSlateBlue;  
        }  
    }

    What is the trick with this and why is it SO HARD to get this to work?  Seems like an incredibly simple to want to do, but it took me 5 minutes to do it with the asp.net controls and I've spent 2 hours on this with the Telerik controls and still can't get it working...  Frustrating.

    Any help?  Thanks!!
    Eddie
  2. Kevin Babcock
    Kevin Babcock avatar
    189 posts
    Member since:
    Mar 2007

    Posted 31 Jul 2008 Link to this post

    Hello Eddie,

    Is there a reason you are trying to set the style properties in your code-behind? You could easily declare those properties in your markup.

    <telerik:RadNumericTextBox ID="RadNumericTextBox1" Runat="server"
        <FocusedStyle BackColor="Blue" BorderWidth="2" /> 
    </telerik:RadNumericTextBox> 

    Are you adding the controls to the Panel dynamically?

    Sincerely,
    Kevin Babcock
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 11 Aug 2008 Link to this post

    Hi,

    Try setting the FocusedStyle in the code behind as shown below.

    CS:
     protected void Page_Load(object sender, EventArgs e)  
        {  
            RadMaskedTextBox1.FocusedStyle.BorderColor = System.Drawing.Color.Red;  
            RadMaskedTextBox1.FocusedStyle.BorderWidth = Unit.Pixel(2);  
     
            RadNumericTextBox1.FocusedStyle.BorderColor = System.Drawing.Color.Blue;  
            RadNumericTextBox1.FocusedStyle.BorderWidth = Unit.Pixel(3);  
        }  
         


    Thanks
    Princy.
Back to Top