473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

CSS doesn't work on dynamicly added user controls

Hi!

I add some web user controls dynamicly with:

myPanel.Controls.Add(Page.LoadControl("MyDynamicly AddedPage.ascx"));
the style of the controls on the user control is set from a css-class, by
setting the CssClass-property, but they doesn't display properly.

If the user control is added at design time everything looks correct.

Any ideas?
Thanks!
/Henke
Nov 18 '05 #1
5 2538
When you add a user control, the control ID may change. If you're using
this ID in any of the styling, then the style will no longer work correctly.

E.g.

<style>
#MyDiv .foo
{
color: #ff2200;
}
</style>

<div id="MyDiv" runat="server" CssClass="foo">This is some text</div>

This will work correctly if added directly at design time. However, if you
put this into a user control, the ID will be changed to something like
"MyUserControl_MyDiv". This will cause the style to stop working, as the
style will only be applied to tags with the ID of "MyDiv".

This might not be your case, but if you can post the style(s) not working,
and a snippet of your code, we can check :-)

Hope this helps,

Mun

"Henke" <he********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi!

I add some web user controls dynamicly with:

myPanel.Controls.Add(Page.LoadControl("MyDynamicly AddedPage.ascx"));
the style of the controls on the user control is set from a css-class, by
setting the CssClass-property, but they doesn't display properly.

If the user control is added at design time everything looks correct.

Any ideas?
Thanks!
/Henke

Nov 18 '05 #2
Hi, and thaks for your quick answer.
I should say I'm not that used to work with css-files but this is how it
looks:
In my css-file:
..Label
{
font-size: 10pt;
font-family: 'Arial Narrow';
}

And than I just set the CssClass property on all my labels on the user
control to Label.

This is how one label looks in "HTML-file" at design time:
<asp:label id="Label8" style="Z-INDEX: 104; LEFT: 8px; POSITION: absolute;
TOP: 24px" runat="server" CssClass="Label">Name *</asp:label>

An this is how the source looks when the page is displayed in a browser:
<span id="dynamicControlHost__ctl0_Label8" class="Label" style="Z-INDEX:
104; LEFT: 8px; POSITION: absolute; TOP: 24px">Name *</span>

/Henke

"Munsifali Rashid" <mun@**RemoveToReply**vefuk.com> skrev i meddelandet
news:e4*************@TK2MSFTNGP09.phx.gbl...
When you add a user control, the control ID may change. If you're using
this ID in any of the styling, then the style will no longer work correctly.
E.g.

<style>
#MyDiv .foo
{
color: #ff2200;
}
</style>

<div id="MyDiv" runat="server" CssClass="foo">This is some text</div>

This will work correctly if added directly at design time. However, if you put this into a user control, the ID will be changed to something like
"MyUserControl_MyDiv". This will cause the style to stop working, as the
style will only be applied to tags with the ID of "MyDiv".

This might not be your case, but if you can post the style(s) not working,
and a snippet of your code, we can check :-)

Hope this helps,

Mun

"Henke" <he********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi!

I add some web user controls dynamicly with:

myPanel.Controls.Add(Page.LoadControl("MyDynamicly AddedPage.ascx"));
the style of the controls on the user control is set from a css-class, by setting the CssClass-property, but they doesn't display properly.

If the user control is added at design time everything looks correct.

Any ideas?
Thanks!
/Henke


Nov 18 '05 #3
There doesn't appear to be anything obviously wrong with the code below.
I'm not sure that 'Arial Narrow' should be in single quotes though - it
should work fine without. However, that wouldn't explain why it works
correctly at design time, but not as a user control.

When you said it doesn't display correctly, what exactly happens? Is the
font incorrect (eg. it appears too big, or is the wrong typeface), or is the
style tag being ignored (eg. the user control is not obeying the absolute
positioning and is not being displayed on the correct part of the page) ?

Regards,

Mun


"Henke" <he********@hotmail.com> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
Hi, and thaks for your quick answer.
I should say I'm not that used to work with css-files but this is how it
looks:
In my css-file:
.Label
{
font-size: 10pt;
font-family: 'Arial Narrow';
}

And than I just set the CssClass property on all my labels on the user
control to Label.

This is how one label looks in "HTML-file" at design time:
<asp:label id="Label8" style="Z-INDEX: 104; LEFT: 8px; POSITION: absolute;
TOP: 24px" runat="server" CssClass="Label">Name *</asp:label>

An this is how the source looks when the page is displayed in a browser:
<span id="dynamicControlHost__ctl0_Label8" class="Label" style="Z-INDEX:
104; LEFT: 8px; POSITION: absolute; TOP: 24px">Name *</span>

/Henke

Nov 18 '05 #4
Both font-size and font-family is incorrect. But I noticed something else,
some user controls get correctly displayed the first time they ar shown, but
the second time the gets displayed the fonts are wrong.
Does it matter if I put my user controls on panels or in place holders?
Now I have a panel on which I loads new user controls depending on some menu
selections.

/Henke

"Munsifali Rashid" <mun.news@#RemoveToReply#cordlessmouse.co.uk> skrev i
meddelandet news:OH**************@TK2MSFTNGP09.phx.gbl...
There doesn't appear to be anything obviously wrong with the code below.
I'm not sure that 'Arial Narrow' should be in single quotes though - it
should work fine without. However, that wouldn't explain why it works
correctly at design time, but not as a user control.

When you said it doesn't display correctly, what exactly happens? Is the
font incorrect (eg. it appears too big, or is the wrong typeface), or is the style tag being ignored (eg. the user control is not obeying the absolute
positioning and is not being displayed on the correct part of the page) ?

Regards,

Mun


"Henke" <he********@hotmail.com> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
Hi, and thaks for your quick answer.
I should say I'm not that used to work with css-files but this is how it
looks:
In my css-file:
.Label
{
font-size: 10pt;
font-family: 'Arial Narrow';
}

And than I just set the CssClass property on all my labels on the user
control to Label.

This is how one label looks in "HTML-file" at design time:
<asp:label id="Label8" style="Z-INDEX: 104; LEFT: 8px; POSITION: absolute; TOP: 24px" runat="server" CssClass="Label">Name *</asp:label>

An this is how the source looks when the page is displayed in a browser:
<span id="dynamicControlHost__ctl0_Label8" class="Label" style="Z-INDEX:
104; LEFT: 8px; POSITION: absolute; TOP: 24px">Name *</span>

/Henke


Nov 18 '05 #5
It shouldn't matter whether your controls are in panels or placeholders.
I've used both in the past, with CSS styling without any problems. Netscape
does some weird things with stylesheets sometimes, but I'm assuming that
you're using Internet Explorer, which shouldn't be a problem.

Mun

"Henke" <he********@hotmail.com> wrote in message
news:O6**************@TK2MSFTNGP09.phx.gbl...
Both font-size and font-family is incorrect. But I noticed something else,
some user controls get correctly displayed the first time they ar shown, but the second time the gets displayed the fonts are wrong.
Does it matter if I put my user controls on panels or in place holders?
Now I have a panel on which I loads new user controls depending on some menu selections.

/Henke

"Munsifali Rashid" <mun.news@#RemoveToReply#cordlessmouse.co.uk> skrev i
meddelandet news:OH**************@TK2MSFTNGP09.phx.gbl...
There doesn't appear to be anything obviously wrong with the code below.
I'm not sure that 'Arial Narrow' should be in single quotes though - it
should work fine without. However, that wouldn't explain why it works
correctly at design time, but not as a user control.

When you said it doesn't display correctly, what exactly happens? Is the font incorrect (eg. it appears too big, or is the wrong typeface), or is

the
style tag being ignored (eg. the user control is not obeying the absolute positioning and is not being displayed on the correct part of the page) ?
Regards,

Mun

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Henke | last post by:
I added a project to my solution that contains a user control. Now I 'd like to add the user control from that project to a form in my solution. The problem is that the control doesn't gets added...
4
by: babylon | last post by:
I created a class which inherits from UserControl.. However, I can't find it in the "My User Controls" tab in designer view... How can i add it back myself? thx...
1
by: Cy Huckaba | last post by:
We are running our company website on a win2k server running .NET framework 1.0 and IIS 5. The pages consist of mostly static content built from a combination of custom controls (dll is only 148k...
1
by: Henke | last post by:
Hi I have a aspx-page with a panel-control. On this panel control I add user controls dynamicly with LoadControl and panel.Controls.Add(myControl). On some of the dynamicly added user controls I...
2
by: DaWoE | last post by:
Hi all, I'm fairly new to ASP.NET. What i want to do is creat a online registration form. On the first step is getting the users details and the number of people he wants to register. Based on...
1
by: Bennett Haselton | last post by:
I create a new Web Form and drag a new Button onto it from the Web Forms toolbox tab, and then I drag a new instance of the UserPost user control that I created, by dragging and dropping the...
1
by: Anders K. Jacobsen [DK] | last post by:
Hi im creating a (or is starting but need your advise) search page for some products which has surdden charataristicas which all should be serachable. These charataristicas can be added runtime so...
4
by: GS | last post by:
Hi, I dynamicly add custom control in SelectedIndexChanged even of GridView which is firing after Page_Load. My control is not being rendered to page becouse of that (I assume). How to avoid this...
6
by: Johnny Jörgensen | last post by:
I've got a usercontrol derived from a normal ComboBox that contains some special formatting code. On my main form I've got a lot of my custom comboboxes. I discovered a bug in the derived...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.