Finishing an Online E-Mail System in ASP.NET 2.0
(Page 1 of 5 )
Yesterday we began designing the interface for an online e-mail system in ASP.NET 2.0. Today, in the conclusion to this four-part series, we pick up where we left off. As you'll recall, the last thing we did was learn how to create folders; in this article, we'll learn how to rename and delete folders, and read and move e-mail.
A
downloadable .rar file is available for this article.
Renaming Folders
In this sample, renaming the folder is achieved through the RenameFolder.aspx, page. Figure 10 shows the relevant design-time snapshot.
Figure 10-the design-time view of the RenameFolder.aspx page

Since there are few controls on the page and their functions can be easily doped out, we choose not to waste time on the controls but to dive right into the associated code.
int nFolderID = -1;
protected void Page_Load(object sender,EventArgs e)
{
///get the value of parameter nFolderID
if(Request.Params["FolderID"] != null)
{
if(Int32.TryParse(Request.Params["FolderID"].ToString(),out nFolderID) == false)
{return;}
}
if(!Page.IsPostBack)
{ ///show name of the folder
if(nFolderID > -1) { BindFolderData(nFolderID); }
}
}
private void BindFolderData(int nFolderID)
{
IFolder folder = new Folder();
SqlDataReader dr = folder.GetSingleFolder(nFolderID);
if(dr.Read())
{
Name.Text = dr["Name"].ToString();
}
dr.Close();
}
Here, when the RenameFolder.aspx page is initialized, we first obtain the value of the nFolderID parameter out of the address bar (of the browser), then call a helper function named BindFolderData which bears the responsibility of grabbing the information of the folder out of the database using the nFolderID parameter, and then displays the folder name in the text box called Name. Next, when you click the OK button (with the id of RenameBtn), renaming is started:
protected void NewBtn_Click(object sender,EventArgs e)
{
try
{ ///define the object
IFolder folder = new Folder();
///execute
folder.RenameFolder(nFolderID,Name.Text.Trim());
Response.Write("<script>alert('" + "Renaming succeeded, safekeep you data!" + "');</script>");
}
catch(Exception ex)
{ ///jump to the page dealing with exception handling
Response.Redirect("ErrorPage.aspx?ErrorMsg=" + ex.Message.Replace("<br>","").Replace("n","")
+ "&ErrorUrl=" + Request.Url.ToString().Replace("<br>","").Replace("n",""));
}
}
Here, when you click the OK button, the NewBtn_Click event is triggered to call the helper function named RenameFolder to rename the folder and persist the new name into the database. Finally, clicking the Return button will navigate you back to the MailDesktop.aspx page.
Next: Deleting Folders >>
More ASP.NET Articles
More By Xianzhong Zhu