view raw
Rafael Sanchez Rafael Sanchez - 8 months ago 37
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="">
<head runat="server">
<title>Send Mail</title>
<form id="form1" runat="server">


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;