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

Changing FocusedStyle in Page_Load?

2 Answers 72 Views
Input
This is a migrated thread and some comments may be shown as answers.
Software
Top achievements
Rank 1
Software asked on 30 Jul 2008, 06:02 PM
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 Answers, 1 is accepted

Sort by
0
Kevin Babcock
Top achievements
Rank 1
answered on 31 Jul 2008, 02:57 PM
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
0
Princy
Top achievements
Rank 2
answered on 11 Aug 2008, 12:40 PM
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.
Tags
Input
Asked by
Software
Top achievements
Rank 1
Answers by
Kevin Babcock
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or