Results 1 to 7 of 7
  1. #1
    Lounger
    Join Date
    May 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Db-driven css styles? (vb.net 2.0)

    Okay, the newest "what if" in my .net experimenting has brought me here-- what would be a good way to go about dynamically changing page styles according to database content? For example, if I had a table that stored background color, text color, and link styles etc etc etc, how could I use them on the page that I am rendering? They can't really be squirted into a style tag or anything, since said tag would need to be located in the head tag, and my .net form is obviously in the page body... I tried looking around with visual studio for something like page.style or page.stylesheet but all I see is page.stylesheettheme which is a string representing the *name* of the theme in use.

    Is there some dot net thing built in that I am missing? Maybe I had heard of something like that a long time ago.

    Any help is appreciated!

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Db-driven css styles? (vb.net 2.0)

    Hi Lancer,

    Welcome to Woody's Lounge!

    One way to do this would be to add the dynamic style information (either a reference to a CSS file or "squirted out" in a <style> tag) to a User Control (ASCX file).

    Create a User Control with only a PlaceHolder control on it. In the code-behind, add the necessary code to generate either the desired <link> or <style> tag. Then add the user control inside the Head tag of the desired ASPX page. (You may want to drag-and-drop the user control onto the page, which will place it inside the Form tag. Then switch to HTML view and copy the tag for the User Control to the desired location within the head tag.)

    Post back if you need additional details.

    Hope this helps!

  3. #3
    Lounger
    Join Date
    May 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Db-driven css styles? (vb.net 2.0)

    So after I have generated the style tag (as only a string) in my usercontrol.ascx.vb file, I would assume that I would need to put that into the placeholder somehow, but there is no placeholder.content or placeholder.text property-- what do I need to do from there...?

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Db-driven css styles? (vb.net 2.0)

    You'll need to create a placeholder control on the User Control. Assign the style data that you've generated to the Text property of the PlaceHolder. You can verify that this is working correctly if you add the User Control into the body of any ASPX page (drag and drop the user control from the Solution Explorer window onto the aspx page in Design view). Then run the page and view its source to verify that the style text is generating correctly.

    Finally, switch to HTML view and move the user control tag from the body of the ASPX page (where you originally dropped it) to the Head tag. Run the page again and you should see the style data inside the head tag and all should be well!

  5. #5
    Lounger
    Join Date
    May 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Db-driven css styles? (vb.net 2.0)

    Yep, the latter part makes sense and should definitely work fine [img]/forums/images/smilies/smile.gif[/img]

    however... visual studio insists that:
    'text' is not a member of 'System.Web.UI.WebControls.PlaceHolder'.

    my ascx file looks like so:
    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="WebUserControl.ascx.vb" Inherits="private_WebUserControl" %>
    <asp:PlaceHolder ID="stylePlaceHolder" runat="server"></asp:PlaceHolder>

    I assumed also that stylePlaceHolder.text = "some style tag" would make things work, but it appears not to be so...
    any ideas?

  6. #6
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Db-driven css styles? (vb.net 2.0)

    My apologies - i forget which object has which properties sometimes. Try a Literal control. Same concept as I mentioned above.

  7. #7
    Lounger
    Join Date
    May 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Db-driven css styles? (vb.net 2.0)

    Ah ha! Much better, and works as expected. Thanks for the help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •