PC Review


Reply
Thread Tools Rate Thread

Converting from asp to asp.net with c#

 
 
Michelle Sollicito eBarster
Guest
Posts: n/a
 
      17th Oct 2008
Ok I know a lot of asp but not a lot of asp.net and C# so please bear
with me. I need some help converting..

In my asp project I have some styles in my head tag that change
according to a parameter passed in in the query string - fontfamily
is the variable that I store the value of the parameter in within my
asp code, and then I place that into the styles see below..

<style type="text/css">
a:link,a:visited,a:hover,a:active{font...
..ebartext{font-family:<%=fontfamily%>;...
..price{font-family:<%=fontfamily%>;fon...
..textfont{font-family:<%=fontfamily%>;...
..{font-family:arial,sans-serif;font-si...
table{background-color:transparent;}
..ebaylogo{position:absolute;z-index:40...
..ebarlogo{position:absolute;z-index:40...
..ebarlogotext{font-family:arial,sans-s...
..ebarcontainer{position:absolute;left:...
..clipdiv{position:absolute;left:0px;to...
</style>

I am not sure how to change my stylesheet from within c# and replace
it with a value passed in as a parameter.

I have gotten the value into the string variable fontfamily, but not
sure how to place that within the style??

//in my c# code default.aspx.cs I get the parameter passed in fine..
string fontfamily = "" + Request.QueryString["fontfamily"];

Can anyone help?
 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      18th Oct 2008
In ASP.NET you will need to do this from within one of the Page events, such
as Load. Here is a class I wrote (with some help from the internet and these
newsgroups):

public class CustomStyle : System.Web.UI.WebControls.Style
{
private System.Web.UI.CssStyleCollection currstyles;

public CustomStyle(System.Web.UI.CssStyleCollection custom) {
this.currstyles = custom; }
public CustomStyle(string cssvalue)
{
System.Web.UI.CssStyleCollection tempstyle = new
System.Web.UI.WebControls.WebControl(System.Web.UI.HtmlTextWriterTag.Unknown).Style;
tempstyle.Clear();
tempstyle.Value = cssvalue;
this.currstyles = tempstyle;
}

protected override void
FillStyleAttributes(System.Web.UI.CssStyleCollection
attributes,System.Web.UI.IUrlResolutionService urlResolver)
{
base.FillStyleAttributes(attributes, urlResolver);
foreach (string currkey in this.currstyles.Keys) { attributes[currkey] =
this.currstyles[currkey]; }
}
}

In your Page's Load event use a statement similar to the following:

this.Header.StyleSheet.CreateStyleRule(new CustomStyle("font-size:12px;"),
null, ".style1");

You will notice that this statement includes two key parts, the
CreateStyleRule method, which you can see details about at:
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref13/html/M_System_Web_UI_IStyleSheet_CreateStyleRule_3_9de1b1b6.htm
For the CreateStyleRule method you will be supplying three parameters, the
Style object returned by a new CustomStyle, null, and a String specifying
the CSS selector.

And the CustomStyle constructor. Although the CustomStyle class has two
constructors, the only one I ever use is the second one, which simply takes
a String of CSS declarations, just as you would enter them in a *.css file,
<style> tags, or HTML style attribute.

It took me a while and a lot of help to figure all this out (I actually got
the original CustomStyle class online, but I had to modify it to include the
second constructor), and I have been doing ASP.NET for a couple years now,
so don't feel bad about not knowing what to do. Hopefully everything I have
supplied will be enough to fix your problem. Good Luck!
--
Nathan Sokalski
(E-Mail Removed)
http://www.nathansokalski.com/

"Michelle Sollicito eBarster" <(E-Mail Removed)> wrote in
message
news:a5a39f71-fbb3-4d7e-b907-(E-Mail Removed)...
> Ok I know a lot of asp but not a lot of asp.net and C# so please bear
> with me. I need some help converting..
>
> In my asp project I have some styles in my head tag that change
> according to a parameter passed in in the query string - fontfamily
> is the variable that I store the value of the parameter in within my
> asp code, and then I place that into the styles see below..
>
> <style type="text/css">
> a:link,a:visited,a:hover,a:active{font...
> .ebartext{font-family:<%=fontfamily%>;...
> .price{font-family:<%=fontfamily%>;fon...
> .textfont{font-family:<%=fontfamily%>;...
> .{font-family:arial,sans-serif;font-si...
> table{background-color:transparent;}
> .ebaylogo{position:absolute;z-index:40...
> .ebarlogo{position:absolute;z-index:40...
> .ebarlogotext{font-family:arial,sans-s...
> .ebarcontainer{position:absolute;left:...
> .clipdiv{position:absolute;left:0px;to...
> </style>
>
> I am not sure how to change my stylesheet from within c# and replace
> it with a value passed in as a parameter.
>
> I have gotten the value into the string variable fontfamily, but not
> sure how to place that within the style??
>
> //in my c# code default.aspx.cs I get the parameter passed in fine..
> string fontfamily = "" + Request.QueryString["fontfamily"];
>
> Can anyone help?



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need some help converting this to C++ AA2e72E Microsoft C# .NET 2 5th Feb 2010 08:19 AM
Re: Converting .lib to .dll Neil Cowburn Microsoft Dot NET Compact Framework 11 19th Jun 2008 05:33 PM
Converting :mm:ss to ss Phredd Microsoft Excel Worksheet Functions 8 18th Jun 2008 07:25 PM
Converting a date to a text field w/o converting it to a julian da LynnMinn Microsoft Excel Worksheet Functions 2 6th Mar 2008 03:43 PM
help converting c# to c++? =?Utf-8?B?Sm9lbA==?= Microsoft Dot NET Framework 11 17th Aug 2006 08:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:29 AM.