Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在html中嵌入字符串_C#_Asp.net - Fatal编程技术网

C# 在html中嵌入字符串

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">&nbsp;<asp:Label ID="Label8"

Asp.NETC# 我正在使用下面的代码

 <%String h = "hello";%>
                 <!-- "wall_com_insert.aspx?Tid=" + Application.Get("Tid");-->



      <div id="content_sr_comment" style="height: auto">&nbsp;<asp:Label ID="Label8" 
              runat="server" Text="<%=h%>" ></asp:Label>
        </div>  

但是我得到了输出

标签上显示的输出:“


我猜语法不对。。我可以获得帮助吗?

您不能将服务器命令放在服务器标记中。试试这个:

<div id="content_sr_comment" style="height: auto">&nbsp;<%= h %></div>


无效页面加载(对象发送方,事件参数e)
{
字符串h=“你好”;
Label8.Text=h;
}

不能将服务器命令放在服务器标记内。试试这个:

<div id="content_sr_comment" style="height: auto">&nbsp;<%= 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">&nbsp;<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">&nbsp;<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>  


谢谢你的工作。。但如果我有多个标签内感谢它的工作。。但是如果我有多个标签在里面呢