Search for rules in HtmlHead.StyleSheet property

J

J055

Hi

I'm adding rules dynamically to the HtmlHead.StyleSheet using the
CreateStyleRule method. I'd like to know how to check whether the rules
already exist first.

Thanks
Andrew
 
S

Steven Cheng[MSFT]

Hi Andrew,

As for the ASP.NET Page.Header.StyleSheet property, I've performed some
research and found that this property is of an internal type, currently we
can only access and manipulate through the two interface
methods(CreateStyleRule and RegisterStyle). And the internal code logical
of "CreateStyleRule" will keep adding the new style rule into an ArrayList
and at runtime, the new rule(added later) will overwrite the former ones. I
think you can make your code logic depend on this behavior. BTW, would you
mind tell us what you'll do that require to inspect the existing rule/style
in the StyleSheet?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
 
J

J055

Hi Steven

The RegisterStyle method doesn't work for me as it only creates a system
names class selector name. I need to set an ID selector with a width based
on the pages currently visible UserControl. What's happening is that it's
very easy to end up with duplicate entries in the page header style element,
e.g.

#container { width:90%; }
#container { width:600px; }

It would be good if there was a way to check for the #container selector or
even better get the styles for the #container too.

I'm thinking that I may need to manage my own way of adding this to the head
element. Any suggestions would be appreciated.

Thanks
Andrew
 
S

Steven Cheng[MSFT]

Thanks for your reply Andrew,

Yes, the current implementation of the Page.Header.StytleSheet is quite
limited.

If you want to manually manage the page inline stylesheet section, you can
consider the following means:

** manually change the <style> tag to "runat=server"

** use codebehind to manipulate it as a LiteralControl(you can customize
the <style> section like a string variable)

======================
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<style id="mystyle" type="text/css" runat="server">

</style>
</head>
...................
====================

================
protected void Page_Load(object sender, EventArgs e)
{
mystyle.InnerText ="#container{width:90%;}";
.........
}
==================

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.











--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top