1 using System; 2 using System.Data; 3 using System.Configuration; 4 using System.Web; 5 using System.Web.Security; 6 using System.Web.UI; 7 using System.Web.UI.WebControls; 8 using System.Web.UI.WebControls.WebParts; 9 using System.Web.UI.HtmlControls; 10 using com.harbormist; 11 12 /// 13 /// The main page 14 /// 15 public partial class _Default : System.Web.UI.Page 16 { 17 //private variable for public property 18 private string _text; 19 20 //remember if a button was clicked 21 //need these to decide to use a default 22 //value or not. 23 private bool emailClicked = false; 24 private bool captionClicked = false; 25 26 /// 27 /// The text to display in the caption 28 /// 29 public string Text 30 { 31 get { return _text; } 32 set { _text = value; } 33 } 34 35 /// 36 /// The url to the image 37 /// 38 public string URL 39 { 40 get 41 { 42 return GlobalInfo.GetInstance().HostAddress + 43 "Image.aspx?message=" + Server.UrlEncode(_text); 44 } 45 } 46 47 48 /// 49 /// Sets the caption text if necessary 50 /// 51 /// 52 /// 53 protected void Page_Load(object sender, EventArgs e) 54 { 55 this.emailResult.Text = ""; 56 _text = LastCaption.Value; 57 } 58 59 protected override void OnPreRender(EventArgs e) 60 { 61 if (emailClicked) 62 { 63 this.Caption.Text = LastCaption.Value; 64 _text = LastCaption.Value; 65 } 66 else if(captionClicked) 67 { 68 _text = Caption.Text; 69 } 70 else 71 { 72 _text = "Default Text"; 73 } 74 LastCaption.Value = _text; 75 76 this.DynamicImage.ImageUrl = this.URL; 77 78 base.OnPreRender(e); 79 } 80 81 /// 82 /// Use the web service to send an email. 83 /// 84 /// 85 /// 86 protected void EmailButton_Click(object sender, EventArgs e) 87 { 88 emailClicked = true; 89 if (IsPostBack) 90 { 91 try 92 { 93 this.emailResult.Text = ""; 94 95 string fromstr, tostr, messagestr, subjectstr; 96 fromstr = this.From.Text.Trim(); 97 tostr = this.To.Text.Trim(); 98 messagestr = this.Message.Text.Trim(); 99 subjectstr = this.Subject.Text.Trim(); 100 101 102 bool valid = true; 103 if (fromstr.Length == 0) 104 { 105 valid = false; 106 this.emailResult.Text += "Please specify a from address.
"; 107 } 108 109 if (tostr.Length == 0) 110 { 111 valid = false; 112 this.emailResult.Text += "Please specify a to address.
"; 113 } 114 115 if (!valid) 116 { 117 this.emailResult.Visible = true; 118 return; 119 } 120 121 DynamicImageGenerator imageGen = new DynamicImageGenerator(); 122 string result = imageGen.sendmail(fromstr, tostr, messagestr, subjectstr, this._text); 123 this.emailResult.Text = "Email Creation Status: " + result; 124 this.emailResult.Visible = true; 125 } 126 catch 127 { 128 this.emailResult.Text = "An error occured while sending email"; 129 this.emailResult.Visible = true; 130 } 131 } 132 } 133 protected void CaptionButton_Click(object sender, EventArgs e) 134 { 135 captionClicked = true; 136 } 137 }