Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply skin to a control created programmatically

I am creating a Textbox in the codebehind of a page like this:

protected override void OnInit(EventArgs e)
{  
      base.OnInit(e);
      TextBox test = new TextBox();
      test.SkinkId = "MySkin";
      placeHolder.Controls.Add(test);
} 

and in my skin file I have this:

<asp:TextBox
    runat="server"
    SkinId = "MySkin"
    Width="400"
/>

Why is the skin not being applied to the control. If I declare the control in my aspx page it works ok, but if I try to do it programmatically it does not work.

like image 327
Luis Avatar asked May 13 '10 07:05

Luis


2 Answers

I know this is an old thread. But i want to share what i had to do to in a similar situation. What helped me is to use ApplyStyleSheetSkin(this) after i created the control.

protected override void OnInit(EventArgs e)
{  
    base.OnInit(e);

    TextBox test = new TextBox();
    test.SkinkId = "MySkin";
    test.ApplyStyleSheetSkin(this); // <--
    placeHolder.Controls.Add(test);
}
like image 152
Dbuggy Avatar answered Sep 27 '22 23:09

Dbuggy


Does it help if you place your code in the OnPreInit event? You might need to add it to the placeholder later, but you could create the control there.

like image 27
Daniel Dyson Avatar answered Sep 28 '22 00:09

Daniel Dyson