Finishing an Online E-Mail System in ASP.NET 2.0 - Reading Your Email
(Page 3 of 5 )
1. The user interface design
Now we'll examine how to read e-mail, which is done through the Reader.aspx page. Figure 11 gives its design-time snapshot.
Figure 11-the design-time snapshot of the Reader.aspx page

Here we use a table to exhibit the controls and their functions.
Id | Control Type | Function |
To | TextBox | The receiver's address (may be more than one) |
CC | TextBox | The email address(es) to whom the email is copied |
Title | TextBox | Title of the email |
Body | TextBox | Body of the email |
AttachView | GridView | Used to show the attachment(s) with the email |
ReceiverBtn | Button | Reply to the receiver(s) (including those to be copied to) |
ReturnBtn | Button | Return to the ViewMail.aspx page |
HtmlCB | HTML checkbox Button | Set the format of the email |
2. Initialization
When initialized, the Reader.aspx page first obtains the parameters named FolderID and MailID from the Request object (which is passed when you click the corresponding hyperlink address of the email in the ViewMail.aspx page):
if(Request.Params["FolderID"] != null)
{
if(Int32.TryParse(Request.Params["FolderID"].ToString(),out nFolderID) == false)
{ return;}
}
if(Request.Params["MailID"] != null)
{
if(Int32.TryParse(Request.Params["MailID"].ToString(),out nMailID) == false)
{ return;}
}
Next, we will display the content of the specified e-mail.
if(!Page.IsPostBack)
{ ///show the content of the mail
if(nMailID > -1)
{
BindMailData(nMailID);
}
}
private void BindMailData(int nMailID)
{
IMail mail = new Mail();
SqlDataReader dr = mail.GetSingleMail(nMailID);
if(dr.Read())
{
Title.Text = dr["Title"].ToString();
CC.Text = dr["CCAddress"].ToString();
To.Text = dr["ToAddress"].ToString();
Body.Text = dr["Body"].ToString();
HtmlCB.Checked = bool.Parse(dr["HTMLFormat"].ToString().ToLower());
SqlDataReader drAttach = mail.GetAttachmentsByMail(nMailID);
AttachView.DataSource = drAttach;
AttachView.DataBind();
drAttach.Close();
}
dr.Close();
}
You can see here that we define a helper function named BindMailData which picks out the detailed information about the email from the underlying database according to the nMailID parameter identifying the email. And also, the corresponding attachment is shown from inside the BindMailData function, with a GridView control (AttachView) to display the content of the attachment. Additionally, when you click the 'New Mail' link from inside the draft box, you can view the email in it, too.
3. Reply and Return
When you click the Reply button on the page, the control is directed to the Sender.aspx page:
protected void RecieverBtn_Click(object sender,EventArgs e)
{ ///reply
Response.Redirect("~/Sender.aspx?MailID=" + nMailID.ToString());
}
And when you click the Return button, you are navigated back to the ViewMail.aspx page.
Next: Deleting Your Email >>
More ASP.NET Articles
More By Xianzhong Zhu