0

I need to change the CONTENTS of a css class through asp.net code behind. The reason why I need to do this is because i have an external user control that uses a property called "stylefolder" instead of the normal cssclass.

I'm really out of ideas, I tried to open the css file and replace text, but then after i also need to save it. So the css file is permantly modified which I don't want.

Please help

1
  • The reason you gave to explain the need for what you expect doesn't convey much. If you have a css class that you do not want to change then create a replica of that class and modify it, and use that instead. Or use inline styling. There can be several solutions, but fact is your problem is not clear. Commented Sep 25, 2013 at 14:04

2 Answers 2

1

The way you are trying to tackle your problem does not seem logical. Temporarily modifying css depending on the stylefolder property seems crazy. Could you not use inline styling depending on the property value and store some data in the session ?

Sign up to request clarification or add additional context in comments.

Comments

0

Make a separate file for that user control and at run time load the file on the condition basis like this

protected void Page_Init(object sender, EventArgs e)
{
  if (usercontrol)
    {
      // load the css relateed to user control
       HtmlLink cssPdf = new HtmlLink();
       cssPdf.Href = "path to user control file";
       cssPdf.Attributes["rel"] = "stylesheet";
       cssPdf.Attributes["type"] = "text/css";
       cssPdf.Attributes["media"] = "all";
       Page.Header.Controls.Add(cssPdf);
    }
  else
    {
      //load regular file
      HtmlLink cssPdf = new HtmlLink();
      cssPdf.Href = "path to regular file";
      cssPdf.Attributes["rel"] = "stylesheet";
      cssPdf.Attributes["type"] = "text/css";
      cssPdf.Attributes["media"] = "all";
      Page.Header.Controls.Add(cssPdf);
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.