Asp.net c# I am using the below code..
<%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>
But I am getting the output..
output displayed on the label: "<%=h开发者_JS百科%>"
I guess the syntax is not correct.. can I get help
You can't place a server command inside a server tag. Try this:
<div id="content_sr_comment" style="height: auto"> <%= h %></div>
Or
<script runat="server" language="C#">
void Page_Load(object sender, EventArgs e)
{
String h = "hello";
Label8.Text = h;
}
</script>
<div id="content_sr_comment" style="height: auto">
<asp:Label ID="Label8" runat="server"></asp:Label>
</div>
This should work:
<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>
Another approach that I find useful, especially if you want to write out a value in multiple places in your html is to create a function in your code behind like this:
protected string SayHello()
{
return "Hello";
}
You can then use it all over your html:
<div id="content_sr_comment" style="height: auto">
<%=SayHello() %>
</div>
精彩评论