nsds
nsds

Reputation: 981

How to write code in html for retrieving the session value.?

I have a Default2.cs file which stores a value in session

TextBox1.Text = "Haii";
    Session["name"] = TextBox1.Text;

and i need to retrieve it in an html page- Default.aspx

   <script runat="server">
Sub Page_Load

  string na=(string)Session["name"];
  Label1.Text=na;
End Sub
</script>

it shows an error 'String' is a class type and cannot be used as an expression. please help

Upvotes: 0

Views: 186

Answers (2)

Bhushan Firake
Bhushan Firake

Reputation: 9458

For ASPX Engine:

Enclose your code in <% Your Code here %>

<% string na=(string)Session["name"]; %>

For Razor Engine:

Enclose your code in @{ Your Code here }

@{ 
    string na=(string)Session["name"];
}

Upvotes: 0

clu3Less
clu3Less

Reputation: 1892

Try this in HTML in Defaul.aspx,

    <% string na=(string)Session["name"]; %>
    <label id="Label1"><% =na %></label>

Upvotes: 1

Related Questions