Rafael Sanchez Rafael Sanchez - 1 year ago 98
ASP.NET (C#) Question

How to Display string text in html body?

I'm just starting with ASP.NET, C# and HTML.

I want to display a text message in the browser if an email was sent successfully.

How do I show in the HTML body the value of a variable that was previously defined in the script part of the


<script runat="server">
void SendAnEmail()
string theResult = "Success! :)";
catch (System.Net.Mail.SmtpException)
string theResult = "Failure! :(";
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Send Mail</title>
<form id="form1" runat="server">

Answer Source

You may want to use the asp:Literal server control which it's syntax is: <asp:Literal runat="server" ID="LiteralText"/>

And assign text to it in code behind: LiteralText.Text = theResult;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download