0

Here the example code

Asp.net 4.5.1 - aspx page

srSelectedLang is a code behind variable

 public string srSelectedLang;//defined at code behind cs file of aspx

the below code is aspx code

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <style type="text/css">

        .setPokemonTeamCSS {
            width: 333px;
            height: 38px;
            display: block;
            background: url(//static.monstermmorpg.com/images/pokemoncenter/set_pokemon_team_<%=srSelectedLang%>.png?3) no-repeat top left;
            border-style: none;
            border-width: 0px;
            cursor: pointer;
        }
          </style>      
</asp:Content>

this example is not working <%=srSelectedLang%>

Furkan Gözükara
  • 22,964
  • 77
  • 205
  • 342

1 Answers1

1

You can't add code behind vars inside a style section...

There are several things you can do:

  1. Manipulate it with JS/jQuery:

    var codeBehindUrl = '<%= string.format("whatever{0}.png",srSelectedLang)%>'

    //on the doc ready method: $(".setPokemonTeamCSS").css("background",codeBehindUrl);

  2. Make a runat=server element and modify CSS from code behind:

    //page:

    < div id="myDiv" runat="server" class="setPokemonTeamCSS">

    //Code begind file:

    myDiv.Style.Add("background",string.format("whatever{0}.png",srSelectedLang) );

Ziv Weissman
  • 4,400
  • 3
  • 28
  • 61