problem dynamic style sheets

.net , Edinburgh, United Kingdom
  • 13 years ago

    Hi guys, i have created a drop down list in the programme i am working on and the user can select which style they would like to apply to the page, this works fine but when the user moves to another  page it returns to the original formatting. I have tried to create a session within the if statement that applies the style but that doesnt work. Any hints would be great.

  • 13 years ago
    I take it that we're talking about stylesheets here? or is this custom styles embedded into the page?
    Can you post the section of code you're working on.
    Difficult to see what's intended by your explanation.
    [If its stylesheets and styles therein, have you double -checked that the link in the header is correct for all pages, as I see no reason why the session variable shouldn't work with Page.StyleSheetTheme = ""]

  • 13 years ago
    I have the same problem.  I am not using the microsoft .net theming method to do it.  I create a table in my database and place my theme names, and theme paths in it.  Then I created a dropdownlist which pulls the themeid and the themename from it.  The problem i am having is I am completley new to C#. I am a coldfsuion web developer and have already acheived this on a site I built.  Now I want to learn how to do it in .net using c#.

    Here we go:
    On my masterpage.master i have this code:

    <!-- pulls the stylesheet from my table when the themon is set to 1 --->
    <asp:Repeater ID="rptSiteCSS" runat="server">
    <link href='<%# DataBinder.Eval(Container.DataItem, "dotNetThemesPath")%>' rel="stylesheet" />   

    <!-- start sites theme section -->
    <div class="side">
    <h2 class="sidebar-title">Site Theme</h2>
    <ul id="recently">
    <li>Current Theme is: <br /><b>(i can pull the theme name later for this, not a prob)</b>
    <br />
        <asp:DropDownList ID="ddlChooseThemes" runat="server" OnSelectedIndexChanged="ChangeThemes" AutoPostBack="True" DataTextField="themeName" AppendDataBoundItems="True" DataValueField="themeid">

    <!-- end login Block section -->

    now my code behind:
    // Gets the themes names for DropDownList //
            if (!IsPostBack)

                objCmd = new System.Data.SqlClient.SqlCommand("SELECT * FROM tblCF_Themes", objConn);
                objRdr = objCmd.ExecuteReader();
                ddlChooseThemes.DataSource = objRdr;
                ddlChooseThemes.DataValueField = "themeid";   
                ddlChooseThemes.DataTextField = "themeName";

            // Begin Return Anonymous StyleSheet from table //
            objCmd = new SqlCommand("SELECT dotNetThemesPath FROM tblCF_Themes WHERE themeon = 1", objConn);
            objRdr = objCmd.ExecuteReader();
            rptSiteCSS.DataSource = objRdr;
            // End Return Anonymous StyleSheet from table //

    All the above works as far as grebbing the theme from my database (like if I change 1 theme to 0 and the other to 1 and then refresh the page, the new style loads.

    I hope this helps others out.  the problems I am having is this:
    I need to know what I am doing wrong with the code below to execute my stored procedure to update then theme for my when I choose from the drop down box:
    // Begin Site Theme Update for Anonymous Users //
         protected void ChangeThemes(object sender, EventArgs e)
                SqlCommand sqlUpdateThemes = new SqlCommand("ag_proc_updateThemes", agwebblogSite_sqlconn);
                sqlUpdateThemes.CommandType = CommandType.StoredProcedure;
                SqlParameter var_themeID = sqlUpdateThemes.Parameters.Add("@aThemeID", SqlDbType.Int);
                //var_themeID.Direction = ParameterDirection.ReturnValue;// ParameterDirection.Input;
                var_themeID.ParameterName = ddlChooseThemes.DataValueField = "themeid";             


                catch (Exception ex)
                    string errormsg = ex.Message.ToString();
        // End Site Theme Update for Anonymous Users //

    And of course the hardest one is how can I set a rule on my master page who is logged in and which query to use for displaying my dynamic styles based on anonymous logged in or logged in???

    Hope my code helps!  Can someone help me too with my problem :(

    thanks so much in advanced.

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook