Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8670059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:37:32+00:00 2026-06-12T18:37:32+00:00

I am trying to set my css theme based on a Request.QueryString variable. My

  • 0

I am trying to set my css theme based on a Request.QueryString variable. My code for selecting which Css theme to use is in a Function, however the function is getting rendered as output instead of getting evaluated and the output being rendered.

Using <%= GetCssTheme() %> makes it render as

<link href="Content/<%= GetCssTheme() %>.css" rel="Stylesheet">

however if I use <%= "" + GetCssTheme() %> it gets correctly rendered as

<link href="Content/ThemeA.css" rel="Stylesheet">

Here’s a small sample that illustrates the problem:

<%@ Page Language="vb" %>

<script language="vbscript" runat="server">
    Public Function GetCssTheme() As String
        Select Case Request.QueryString("SomeValue")
            Case 2
                Return "ThemeB"
            Case 3
                Return "ThemeC"
            Case Else
                Return "ThemeA"
        End Select
    End Function
</script>


<html>
<head runat="server">
    <link href="Content/<%= GetCssTheme() %>.css" rel="Stylesheet" />
</head>
<body>
    Test
</body>
</html>

Why do I need to specify a blank string in front of my function name for it to work?

I have tried various other methods too:

  • Using single quotes instead of double quotes

  • Using<%= GetCssTheme().ToString() %>

  • Using <% Response.Write(GetCssTheme()) %>

  • Using

<%
    Dim s as String
    s = GetCssTheme()
    Response.Write(s)
%>

All of these incorrectly render the ASP.Net code itself instead of evaluating it and outputting the result.

The only thing I tried that does actually work is using in-line code instead of calling the function, or add a blank string to the function call.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:37:33+00:00Added an answer on June 12, 2026 at 6:37 pm

    The issue is because of the runat=”server” on your head tag. If you take it away the code will work just fine. This seems to be an old issue…

    This URL shows the problem much like our dialog has been on this question, but has no cause.

    http://geekswithblogs.net/mnf/archive/2007/11/14/code-render-blocks-not-always-work-inside-server-controls.aspx

    So, if you don’t need the runat=”server” on your head tag, that will fix the issues…alternatively, if you do, you can always place the LINK tag at the start of the body which is not ideal.

    I’ll continue to look, but I think this is either a side effect of other functionality or it is a bug in ASP.NET.

    UPDATE:

    I found this other SO question which specifies the cause. –
    Inline code in head tag – ASP.NET

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am trying to use the CSS hack to set the max-height for
I am trying to set DIV width based on the child image. This code
I am trying to set up a simple css transition where there is a
I'm trying to set the CSS style of an object with the following: document.getElementById(obj).style='font-weight:bold;
In ASP.NET MVC3 I'm trying to set the css class that the validation error
Using jQuery I am trying to set focus for (CSS purposes) to a particular
I'm trying to get the width of a div container to set another css
I'm developing a wordpress theme locally and I'm trying to set a base URL
I'm just trying to set up an input with datepicker and I'm getting the
I'm using vendor prefixed css transitions, based on this demo , which seems to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.