C# 在html中嵌入字符串
Asp.NETC# 我正在使用下面的代码C# 在html中嵌入字符串,c#,asp.net,C#,Asp.net,Asp.NETC# 我正在使用下面的代码 <%String h = "hello";%> <!-- "wall_com_insert.aspx?Tid=" + Application.Get("Tid");--> <div id="content_sr_comment" style="height: auto"> <asp:Label ID="Label8"
<%String h = "hello";%>
<!-- "wall_com_insert.aspx?Tid=" + Application.Get("Tid");-->
<div id="content_sr_comment" style="height: auto"> <asp:Label ID="Label8"
runat="server" Text="<%=h%>" ></asp:Label>
</div>
但是我得到了输出
标签上显示的输出:“
我猜语法不对。。我可以获得帮助吗?您不能将服务器命令放在服务器标记中。试试这个:
<div id="content_sr_comment" style="height: auto"> <%= h %></div>
或
无效页面加载(对象发送方,事件参数e)
{
字符串h=“你好”;
Label8.Text=h;
}
不能将服务器命令放在服务器标记内。试试这个:
<div id="content_sr_comment" style="height: auto"> <%= h %></div>
或
无效页面加载(对象发送方,事件参数e)
{
字符串h=“你好”;
Label8.Text=h;
}
这应该可以:
<script runat="server" language="C#">
private string h = "hello";
</script>
<!-- "wall_com_insert.aspx?Tid=" + Application.Get("Tid");-->
<div id="content_sr_comment" style="height: auto"> <asp:Label ID="Label8"
runat="server"><%=h%></asp:Label>
</div>
私有字符串h=“hello”;
这应该可以:
<script runat="server" language="C#">
private string h = "hello";
</script>
<!-- "wall_com_insert.aspx?Tid=" + Application.Get("Tid");-->
<div id="content_sr_comment" style="height: auto"> <asp:Label ID="Label8"
runat="server"><%=h%></asp:Label>
</div>
私有字符串h=“hello”;
我发现另一种有用的方法,特别是如果您想在html中的多个位置写出一个值,可以在代码中创建一个函数,如下所示:
protected string SayHello()
{
return "Hello";
}
然后,您可以在整个html中使用它:
<div id="content_sr_comment" style="height: auto">
<%=SayHello() %>
</div>
我发现另一种有用的方法,特别是如果您想在html中的多个位置写出一个值,可以在代码中创建一个函数,如下所示:
protected string SayHello()
{
return "Hello";
}
然后,您可以在整个html中使用它:
<div id="content_sr_comment" style="height: auto">
<%=SayHello() %>
</div>
谢谢你的工作。。但如果我有多个标签内感谢它的工作。。但是如果我有多个标签在里面呢