1

I have a page with a Textbox, a Button and a Label control. On Button_Click event, I store the value of Textbox in a variable called S using code behind.

How do I show the value of S in the Label control using inline code, but not using the code behind?

2 Answers 2

4

This is not the ASP.NET approach, but you can add S as a member of the code-behind class (at least protected):

protected string S { get; private set; }

And retrieve it inline in the page markup with

<%= S %>
0

I am not exactly sure about the requirement, but following with some modifications it will work. Embed this block in your aspx page:

If using C#

<script runat="server">
    void Page_Load(Object sender, EventArgs e)
    {
       mylabel.Text = s; // Replace with your label control
    }
</script>

If using VB.NET:

<script runat="server">
    Sub Page_Load(Sender As Object, E As EventArgs)
        mylabel.Text = s
    End Sub
</script>

Your Answer

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