473,471 Members | 4,629 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamically creating CSS

I have a User Control (.ascx & .ascx.vb) for which I need to dynamically
specify certain CSS stylesheet properties. Because the controls that I use
in the .ascx file do not list style as one of their properties (they list
CssClass, but but not a place where I can enter either a string or
property/value pairs). In the past when making pages I would type the Style=
attribute even though Visual Studio doesn't list it as an available
property. I have found the Style class and the
HtmlTextWriter.AddStyleAttribute method, but all the examples I have found
override Style.AddAttributesToRender and are in a non-ascx control (they are
not in controls that are built from existing controls). Could someone send
me a basic example of how to dynamically add style properties to an .ascx
user control? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
1 1180
Because ASCX controls do not necessary equate to a single HTML element,
there is no way for the browser to apply the style as it one can ask, "which
element should the style be applied to?"

Having said that, you can still create a style property for your control,
and then before the control renders, just apply the style as appropriate.

For instance,

public string Style{
get{...}
set{...}
}

<uc1:MyControl ... Style="..."/>

protected void OnPreRender(...){
// use the style as you see fit.
}

(by the way, this is c#, you can apply the same concept to your VB code.)
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:u3**************@TK2MSFTNGP14.phx.gbl...
I have a User Control (.ascx & .ascx.vb) for which I need to dynamically
specify certain CSS stylesheet properties. Because the controls that I use
in the .ascx file do not list style as one of their properties (they list
CssClass, but but not a place where I can enter either a string or
property/value pairs). In the past when making pages I would type the
Style= attribute even though Visual Studio doesn't list it as an available
property. I have found the Style class and the
HtmlTextWriter.AddStyleAttribute method, but all the examples I have found
override Style.AddAttributesToRender and are in a non-ascx control (they
are not in controls that are built from existing controls). Could someone
send me a basic example of how to dynamically add style properties to an
.ascx user control? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #2

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

Similar topics

2
by: djc | last post by:
On the page_load event I am querying a database and binding data to some text boxes, list boxes, and a repeater control. When the page loads it uses the value of one of the database fields (status)...
2
by: Patrick | last post by:
I want to define a set of web-form templates in XML and render the equivalent web-form with ASP.NET, then process any input server controls on the form. Reading the XML file from Page_load is...
3
by: Dotnet Gruven | last post by:
I've built a WebForm with a Table added dynamically in Page_Load when IsPostBack is false. The table includes a couple of TextBoxes, RadioButtonLists and CheckboxLists. On postback, those...
6
by: Tex | last post by:
I am writting a survey system web application. I am using ASP.Net 2, C# and MS SQL 2005. I am able to store surveys and questions associated to the surveys just fine. The problem I am having is...
9
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related...
6
by: Bjorn Sagbakken | last post by:
Hello In VS2005: I am adding buttons and textboxes dynamically into a table, that also dynamically expands. So far, so good, actually very nice. But I am having trouble starting the desired...
0
by: lianaent | last post by:
Hi All, I'm brand new to asp.net 2.0, and have a simple task of just creating a quick and dirty data entry form with SQL Server 2005 on the back end. I added a gridview to my form, and I can...
5
by: Nathan Sokalski | last post by:
I have a custom control that I wrote (I inherit from System.Web.UI.WebControls.CompositeControl). I dynamically add this control to my Page, but I was told that dynamically added controls do not...
4
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
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...
1
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
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.