这里是示例代码
Asp.net 4.5.1 - aspx页面
<label-option for="checkbox">
<input type="checkbox" checked="false" name="single" id="single"> Single Status
</label-option>
是变量背后的代码
srSelectedLang
以下代码是aspx代码
public string srSelectedLang;//defined at code behind cs file of aspx
此示例无效<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>
答案 0 :(得分:1)
您无法在样式部分内的代码后面添加代码...
你可以做几件事:
使用JS / jQuery操作它:
var codeBehindUrl =&#39;&lt;%= string.format(&#34;无论{0} .png&#34;,srSelectedLang)%&gt;&#39;
//在doc ready方法上: $(&#34; .setPokemonTeamCSS&#34)的CSS。(&#34;背景&#34;,codeBehindUrl);
创建一个runat = server元素并从后面的代码中修改CSS:
//页:
&LT; div id =&#34; myDiv&#34; RUNAT =&#34;服务器&#34;类=&#34; setPokemonTeamCSS&#34;&GT;
//代码文件:
myDiv.Style.Add(&#34; background&#34;,string.format(&#34;无论{0} .png&#34;,srSelectedLang));