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.
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);
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With