Reputation: 409
First I have index.aspx and below that there is a c# class called index.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Index : Page
{
public string test = "hello";
protected void Page_Load(object sender, EventArgs e)
{
test = "Hello lesley";
}
}
But how can I show the value of the 'test' string in the html page?
Upvotes: 2
Views: 913
Reputation: 894
Alternatively, if you already have that property in your index.aspx.cs, you can do this in index.aspx html page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
Hi <b><%=test%></b>
</form>
</body>
Upvotes: 2
Reputation: 461
Try this
protected void Page_Load(object sender, EventArgs e)
{
test = "Hello lesley";
Label label = new Label();
label.Text = test;
Page.Controls.Add(label);
}
Upvotes: 2