Soulzityr
Soulzityr

Reputation: 456

On Page_Load, replace HTML text with generated text

So my HTML looks a little bit like this:

<tr>
    <td>@@Street@@</td>
</tr>
<tr>
    <td>@@CityStateZip@@<br />
    <br />
    <br />
    <br />
    </td>
</tr>

So on my C# page, on Page_Load, I want to replace @@Street@@ and @@CityStateZip@@ with the actual value. For example, I want to do something like this.

string.Replace("@@Street@@","123 Sample Street");

and then when the page fully loads, it will show 123 Sample Street instead of @@Street@@

Is there any way to do this? If not, how would I accomplish this alternatively?

Upvotes: 0

Views: 287

Answers (2)

SoftSan
SoftSan

Reputation: 2472

<tr>
    <td><asp:Label id="streetLabel" runat="server" /></td>
</tr>
<tr>
    <td><asp:Label id="cityZipLabel" runat="server" /><br />
    <br />
    <br />
    <br />
    </td>
</tr>

in your page load:

Page_load()
{
if(!isPostBack)
{
   streetLabel.Text= "Replace your text here";
}
}

Upvotes: 1

Andrew
Andrew

Reputation: 20091

Use labels

eg:

For this label:

<asp:label id="lblStreet" runat="server" />

In the code behind use (C#):

lblStreet.Text = "Sample Street"; 

How do I set an ASP.NET Label text from code behind on page load?

Upvotes: 0

Related Questions