0

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">&nbsp;<asp:Label ID="Label8" 
              runat="server" Text="<%=h%>" ></asp:Label>
        </div>  

But I am getting the output..

output displayed on the label: "<%=h%>"

I guess the syntax is not correct.. can I get help

3 Answers 3

2

You can't place a server command inside a server tag. Try this:

<div id="content_sr_comment" style="height: auto">&nbsp;<%= 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">&nbsp;
    <asp:Label ID="Label8" runat="server"></asp:Label>
</div>  
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks its working.. but what if I have multiple label tag inside <div></div>
1

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">&nbsp;<asp:Label ID="Label8" 
    runat="server"><%=h%></asp:Label>
</div>  

Comments

1

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>  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.