473,695 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding Style at run time

Hello,
I am a ASPX page where I have defined the style for the head element.
*************** ***
<head runat="server" >
<style type="text/css">
.MyClass
{
background-color: aqua;
}
</style>
</head>
*************** ***

However, instead of doing at design time, I need to do this at run time..
Can someone help how to add this @ run time to the page?.

Thanks,
Ganesh
Aug 25 '06 #1
8 2465
You could declare the link id for the stylesheet with a runat sever tag and
use an external stylesheet

<head>
<link id="cssStyleShe et" rel="stylesheet " type="text/css" runat="server" />
</head>
Sub Page_Load(Sende r As Object, E As EventArgs)
If Not (IsPostBack)
cssStyleSheet.A ttributes.Add(" href","Styleshe etname.css")
End If
End Sub

--
Regards

John Timney (MVP)

"Ganesh Muthuvelu" <Ga************ *@discussions.m icrosoft.comwro te in
message news:37******** *************** ***********@mic rosoft.com...
Hello,
I am a ASPX page where I have defined the style for the head element.
*************** ***
<head runat="server" >
<style type="text/css">
.MyClass
{
background-color: aqua;
}
</style>
</head>
*************** ***

However, instead of doing at design time, I need to do this at run time..
Can someone help how to add this @ run time to the page?.

Thanks,
Ganesh

Aug 25 '06 #2
Hi Ganesh,

Here's some code that creates a style in code at runtime.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArg s)
' Instantiate a style object
Dim styl As New Style
' Set the style (e.g., background colour)
styl.BackColor = Drawing.Color.A qua
' Assign the style, URL [nothing here] and selector
Page.Header.Sty leSheet.CreateS tyleRule _
(styl, Nothing, ".MyClass")
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="header1" runat="server">
<title>Creati ng a style at runtime</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:label cssclass="MyCla ss" id="Label1" runat="server" text="Style
created in code"></asp:label></div>
</form>
</body>
</html>
"Ganesh Muthuvelu" <Ga************ *@discussions.m icrosoft.comwro te in
message news:37******** *************** ***********@mic rosoft.com...
Hello,
I am a ASPX page where I have defined the style for the head element.
*************** ***
<head runat="server" >
<style type="text/css">
.MyClass
{
background-color: aqua;
}
</style>
</head>
*************** ***

However, instead of doing at design time, I need to do this at run time..
Can someone help how to add this @ run time to the page?.

Thanks,
Ganesh

Aug 25 '06 #3
Check out the new classes related to the head element buy using this search
term...

HtmlHead class site:msdn2.micr osoft.com

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee. com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

"Ken Cox [Microsoft MVP]" <BA**********@n ewsgroups.nospa mwrote in message
news:ep******** ******@TK2MSFTN GP03.phx.gbl...
Hi Ganesh,

Here's some code that creates a style in code at runtime.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArg s)
' Instantiate a style object
Dim styl As New Style
' Set the style (e.g., background colour)
styl.BackColor = Drawing.Color.A qua
' Assign the style, URL [nothing here] and selector
Page.Header.Sty leSheet.CreateS tyleRule _
(styl, Nothing, ".MyClass")
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="header1" runat="server">
<title>Creati ng a style at runtime</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:label cssclass="MyCla ss" id="Label1" runat="server"
text="Style created in code"></asp:label></div>
</form>
</body>
</html>
"Ganesh Muthuvelu" <Ga************ *@discussions.m icrosoft.comwro te in
message news:37******** *************** ***********@mic rosoft.com...
>Hello,
I am a ASPX page where I have defined the style for the head element.
************** ****
<head runat="server" >
<style type="text/css">
.MyClass
{
background-color: aqua;
}
</style>
</head>
************** ****

However, instead of doing at design time, I need to do this at run time..
Can someone help how to add this @ run time to the page?.

Thanks,
Ganesh


Aug 25 '06 #4
Thanks John,
But now how would I add the "link" tag at run time?.

Thanks,
Ganesh

"John Timney (MVP)" wrote:
You could declare the link id for the stylesheet with a runat sever tag and
use an external stylesheet

<head>
<link id="cssStyleShe et" rel="stylesheet " type="text/css" runat="server" />
</head>
Sub Page_Load(Sende r As Object, E As EventArgs)
If Not (IsPostBack)
cssStyleSheet.A ttributes.Add(" href","Styleshe etname.css")
End If
End Sub

--
Regards

John Timney (MVP)

"Ganesh Muthuvelu" <Ga************ *@discussions.m icrosoft.comwro te in
message news:37******** *************** ***********@mic rosoft.com...
Hello,
I am a ASPX page where I have defined the style for the head element.
*************** ***
<head runat="server" >
<style type="text/css">
.MyClass
{
background-color: aqua;
}
</style>
</head>
*************** ***

However, instead of doing at design time, I need to do this at run time..
Can someone help how to add this @ run time to the page?.

Thanks,
Ganesh


Aug 25 '06 #5
Mine doesn't work?

"clintonG" <cs*********@RE MOVETHISTEXTmet romilwaukee.com wrote in message
news:eB******** ******@TK2MSFTN GP06.phx.gbl...
Check out the new classes related to the head element buy using this
search term...

HtmlHead class site:msdn2.micr osoft.com

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee. com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

"Ken Cox [Microsoft MVP]" <BA**********@n ewsgroups.nospa mwrote in
message news:ep******** ******@TK2MSFTN GP03.phx.gbl...
>Hi Ganesh,

Here's some code that creates a style in code at runtime.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArg s)
' Instantiate a style object
Dim styl As New Style
' Set the style (e.g., background colour)
styl.BackColor = Drawing.Color.A qua
' Assign the style, URL [nothing here] and selector
Page.Header.Sty leSheet.CreateS tyleRule _
(styl, Nothing, ".MyClass")
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="header1" runat="server">
<title>Creati ng a style at runtime</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:label cssclass="MyCla ss" id="Label1" runat="server"
text="Style created in code"></asp:label></div>
</form>
</body>
</html>
"Ganesh Muthuvelu" <Ga************ *@discussions.m icrosoft.comwro te in
message news:37******** *************** ***********@mic rosoft.com...
>>Hello,
I am a ASPX page where I have defined the style for the head element.
************* *****
<head runat="server" >
<style type="text/css">
.MyClass
{
background-color: aqua;
}
</style>
</head>
************* *****

However, instead of doing at design time, I need to do this at run
time..
Can someone help how to add this @ run time to the page?.

Thanks,
Ganesh



Aug 25 '06 #6
PERFECT!!! KEN, THANKS A BUNCH!

"Ken Cox [Microsoft MVP]" wrote:
Hi Ganesh,

Here's some code that creates a style in code at runtime.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArg s)
' Instantiate a style object
Dim styl As New Style
' Set the style (e.g., background colour)
styl.BackColor = Drawing.Color.A qua
' Assign the style, URL [nothing here] and selector
Page.Header.Sty leSheet.CreateS tyleRule _
(styl, Nothing, ".MyClass")
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="header1" runat="server">
<title>Creati ng a style at runtime</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:label cssclass="MyCla ss" id="Label1" runat="server" text="Style
created in code"></asp:label></div>
</form>
</body>
</html>
"Ganesh Muthuvelu" <Ga************ *@discussions.m icrosoft.comwro te in
message news:37******** *************** ***********@mic rosoft.com...
Hello,
I am a ASPX page where I have defined the style for the head element.
*************** ***
<head runat="server" >
<style type="text/css">
.MyClass
{
background-color: aqua;
}
</style>
</head>
*************** ***

However, instead of doing at design time, I need to do this at run time..
Can someone help how to add this @ run time to the page?.

Thanks,
Ganesh


Aug 25 '06 #7
Hi Ganesh,

You're welcome, and here's a further reference that I just found:

http://msdn2.microsoft.com/en-us/lib...stylerule.aspx

"Ganesh Muthuvelu" <Ga************ *@discussions.m icrosoft.comwro te in
message news:E0******** *************** ***********@mic rosoft.com...
PERFECT!!! KEN, THANKS A BUNCH!

"Ken Cox [Microsoft MVP]" wrote:
>Hi Ganesh,

Here's some code that creates a style in code at runtime.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArg s)
' Instantiate a style object
Dim styl As New Style
' Set the style (e.g., background colour)
styl.BackColor = Drawing.Color.A qua
' Assign the style, URL [nothing here] and selector
Page.Header.Sty leSheet.CreateS tyleRule _
(styl, Nothing, ".MyClass")
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="header1" runat="server">
<title>Creati ng a style at runtime</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:label cssclass="MyCla ss" id="Label1" runat="server"
text="Style
created in code"></asp:label></div>
</form>
</body>
</html>
"Ganesh Muthuvelu" <Ga************ *@discussions.m icrosoft.comwro te in
message news:37******** *************** ***********@mic rosoft.com...
Hello,
I am a ASPX page where I have defined the style for the head element.
*************** ***
<head runat="server" >
<style type="text/css">
.MyClass
{
background-color: aqua;
}
</style>
</head>
*************** ***

However, instead of doing at design time, I need to do this at run
time..
Can someone help how to add this @ run time to the page?.

Thanks,
Ganesh



Aug 26 '06 #8
Sure, that code snippet works fine Ken but the context of the head element
is much broader than a snippet infers so I thought I'd throw in the big
picture in case the OP is a serious developer who may be currently ignorant
but wants to learn how to master the framework. Once finding and loading the
documentation for a class such as the HtmlHead class the menu for MSDN
documentation will also display all the related classes such as HtmlLink,
HtmlMeta and so on. Very insightful wouldn't you agree?

As you may recall, one of the most frequently asked questions used to be
"[should I | how do I] do this using my own code or is there a class already
built in the framework?" That was early in the days when those who really
wanted to learn to be masterful were interested in delving into the
framework.

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee. com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

"Ken Cox [Microsoft MVP]" <BA**********@n ewsgroups.nospa mwrote in message
news:ew******** ******@TK2MSFTN GP02.phx.gbl...
Mine doesn't work?

"clintonG" <cs*********@RE MOVETHISTEXTmet romilwaukee.com wrote in message
news:eB******** ******@TK2MSFTN GP06.phx.gbl...
>Check out the new classes related to the head element buy using this
search term...

HtmlHead class site:msdn2.micr osoft.com

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee. com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

"Ken Cox [Microsoft MVP]" <BA**********@n ewsgroups.nospa mwrote in
message news:ep******** ******@TK2MSFTN GP03.phx.gbl...
>>Hi Ganesh,

Here's some code that creates a style in code at runtime.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArg s)
' Instantiate a style object
Dim styl As New Style
' Set the style (e.g., background colour)
styl.BackColor = Drawing.Color.A qua
' Assign the style, URL [nothing here] and selector
Page.Header.Sty leSheet.CreateS tyleRule _
(styl, Nothing, ".MyClass")
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="header1" runat="server">
<title>Creati ng a style at runtime</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:label cssclass="MyCla ss" id="Label1" runat="server"
text="Style created in code"></asp:label></div>
</form>
</body>
</html>
"Ganesh Muthuvelu" <Ga************ *@discussions.m icrosoft.comwro te in
message news:37******** *************** ***********@mic rosoft.com...
Hello,
I am a ASPX page where I have defined the style for the head element.
************ ******
<head runat="server" >
<style type="text/css">
.MyClass
{
background-color: aqua;
}
</style>
</head>
************ ******

However, instead of doing at design time, I need to do this at run
time..
Can someone help how to add this @ run time to the page?.

Thanks,
Ganesh




Aug 26 '06 #9

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

Similar topics

4
2370
by: Max Derkachev | last post by:
Good day to all. Some time ago I'd been playing with a framework which uses dynamic class creation havily. Say, I could do: class A: pass # I method name is dynamic meth_name = 'foo'
10
1169
by: xxbmichae1 | last post by:
I'm having a hard time getting this code to work...the onMouseOver and onMouseOut events don't seem to be firing in IE or Mozilla.....thanks in advance for any assistance... var imgf = document.createElement("img"); imgf.src = "../files/img.gif"; imgf.style.cursor = "pointer"; imgf.style.border = "1px solid blue"; imgf.title = "Date selector";
32
2145
by: Ed Jay | last post by:
A complete js newbie is asking this question: I have a form comprised of several questions, each answered with a radio button. I'd like to use onClick to bring up additional text at the end of the form (not in a text box). I've tried using document.write("yada"), but it clears the page before showing the text. How can I do it? BTW, I'm currently using js in conjunction with CSS to unhide the text. This works fine, except it requires...
3
1373
by: The Crow | last post by:
how does it affect performance and memory consumption? i think there will be no difference memory consumption per instance.
4
2496
by: Bas Groeneveld | last post by:
I am developing an ASP.NET application part of which consists of a data entry wizard defined by entries in a data table - ie the controls on each page of the wizard are determined by definitions in the table. I know that I can dynamically add controls (eg a textbox) to the page controls collection of a web form in a server event which will then be rendered onto the form, as in the following snippet: System.Web.UI.WebControls.TextBox...
17
12782
by: Sri | last post by:
How do you add an n-bit number in C? Regards, Sri
11
11199
by: Daz | last post by:
Hello everyone. I am sure the answer to my question is simple, but I can't seem to dynamically add an onClick event to my script. I have a table which is generated dynamically, I am just struggling getting an onClick event to show in the HTML source. Any help would be appreciated. Here is a block of my current code which doesn't work. var tr1 = document.createElement('tr');
2
7661
by: Ken Fine | last post by:
I want to add the security question and answer security feature to the ChangePassword control. I am aware that this functionality is built into the PasswordRecovery tool. I have implemented the PasswordRecovery with a Password reset required; a temporary password is sent to the account on file. I want an extra layer of security to accommodate the very unlikely contingency that someone's e-mail account is compromised. Challenging with the...
1
4897
by: swethak | last post by:
Hi, I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the events when click on that date that perticular event displyed in a text box.But my requirement is to when click on that date that related event displyed in same td row not the text box. and also i add the events to that calendar.plz advice how to...
0
8628
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8567
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8981
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8823
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7660
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5839
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4340
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2271
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.