using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using com.harbormist; /// /// The main page /// public partial class _Default : System.Web.UI.Page { //private variable for public property private string _text; //remember if a button was clicked //need these to decide to use a default //value or not. private bool emailClicked = false; private bool captionClicked = false; /// /// The text to display in the caption /// public string Text { get { return _text; } set { _text = value; } } /// /// The url to the image /// public string URL { get { return GlobalInfo.GetInstance().HostAddress + "Image.aspx?message=" + Server.UrlEncode(_text); } } /// /// Sets the caption text if necessary /// /// /// protected void Page_Load(object sender, EventArgs e) { this.emailResult.Text = ""; _text = LastCaption.Value; } protected override void OnPreRender(EventArgs e) { if (emailClicked) { this.Caption.Text = LastCaption.Value; _text = LastCaption.Value; } else if(captionClicked) { _text = Caption.Text; } else { _text = "Default Text"; } LastCaption.Value = _text; this.DynamicImage.ImageUrl = this.URL; base.OnPreRender(e); } /// /// Use the web service to send an email. /// /// /// protected void EmailButton_Click(object sender, EventArgs e) { emailClicked = true; if (IsPostBack) { try { this.emailResult.Text = ""; string fromstr, tostr, messagestr, subjectstr; fromstr = this.From.Text.Trim(); tostr = this.To.Text.Trim(); messagestr = this.Message.Text.Trim(); subjectstr = this.Subject.Text.Trim(); bool valid = true; if (fromstr.Length == 0) { valid = false; this.emailResult.Text += "Please specify a from address.
"; } if (tostr.Length == 0) { valid = false; this.emailResult.Text += "Please specify a to address.
"; } if (!valid) { this.emailResult.Visible = true; return; } DynamicImageGenerator imageGen = new DynamicImageGenerator(); string result = imageGen.sendmail(fromstr, tostr, messagestr, subjectstr, this._text); this.emailResult.Text = "Email Creation Status: " + result; this.emailResult.Visible = true; } catch { this.emailResult.Text = "An error occured while sending email"; this.emailResult.Visible = true; } } } protected void CaptionButton_Click(object sender, EventArgs e) { captionClicked = true; } }