Search code examples
c#asp.netdynamic-data

Access variable in aspx.cs file and display in text box


Here is my Emial.Aspx.cs file. I have a public variable called loginEmail.

public String loginEmail;

protected void Page_Load(object sender, EventArgs e){
loginEmail= Session["Email"].ToString();
}

I want to display that variable in bellow textbox. But this is not worked for me.

<td>
   <asp:TextBox ID="TextBox_name" runat="server" Text = "<%= loginEmail %>";></asp:TextBox>
</td>

Error:

Parser Error Message: Server tags cannot contain <% ... %> constructs.

Please help me.


Solution

  • In the page Load event

    TextBox_name.Text = loginEmail;