User Information Management for an ASP.NET AJAX Server-Centric Based Online Shopping Website - Page Initialization
(Page 3 of 4 )
Page Initialization
When the page is initialized, we should finish the task of loading the original user data and display it to them.
protected void Page_Load(object sender,EventArgs e) {
///Get the value of the parameter
if(Request.Params["UserID"] != null) {
if(Int32.TryParse(Request.Params["UserID"].ToString(),out nUserID) == false) {
return;
}
}
if(!Page.IsPostBack) {
///bind data to the control
if(nUserID > -1) {
BindUserData(nUserID);
}
}
SureBtn.Enabled = nUserID <= -1 ? false : true;
}
private void BindUserData(int nUserID) {
///Get the data
User user = new User();
SqlDataReader recr = user.GetSingleUser(nUserID);
///Read the data
if(recr.Read()){
///display data
UserName.Text = recr["UserName"].ToString();
RealName.Text = recr["RealName"].ToString();
Email.Text = recr["Email"].ToString();
Phone.Text = recr["Phone"].ToString();
Mobile.Text = recr["Mobile"].ToString();
Remark.Text = recr["Remark"].ToString();
Address.Text = recr["Address"].ToString();
}
recr.Close(); ///Close the data source
}
Here we still provide enough comments to which you can refer. Please remember that no matter which page you analyze in this sample, the basic initialization logic is quite similar. That will help you find your focus.
Submitting the Modification
Clicking the "OK" button will trigger its corresponding event handler, as follows:
protected void SureBtn_Click(object sender,EventArgs e){
User user = new User();
user.UpdateUser(nUserID,RealName.Text,
Address.Text,Phone.Text,Mobile.Text,
Email.Text,Remark.Text);
Response.Write("<script>window.alert('Changing user info successfully!')</script>");
}
Here, we first create an instance of the User class, and then invoke its UpdateUser member functionto finally submit the personal information to change the server side database. That’s it. As for the inner workings relating to UpdateUseritself, please refer to the downloadable source code accompanying this article.
Next: Viewing Personal Info >>
More ASP.NET Articles
More By Xianzhong Zhu