点击返回目录->
前言
紧接上篇->基于C#开发web网页管理系统模板流程-主界面统计功能完善-CSDN博客
一个合格的管理系统,至少一定存在一个功能——用户能够自己修改密码,理论上来说密码只能有用户自己一个人知道,就算是数据库中存储的密码记录,在实际开发应用中也应是严格加密后的密文(即开发人员也无法查看用户的密码)
本篇就来实现用户修改密码的功能,其实现本质其实很简单:接收用户输入的新密码->判断新密码合法性->使用update语句更新数据库中的密码记录
希望你养成这个好习惯,将不同功能的脚本分门别类的放在不同的文件夹中
创建一个【包含母版页的Web窗体】,将其命名为mmwh.aspx(密码维护)
点击添加后再弹出的【选择母版页】窗口中选择唯一一个母版页Site.Master

密码维护的界面算得上是十分简单的了,两种很熟悉的控件,而且不需要做什么设置

打开【mmwh.aspx.cs】文件,将下面的代码复制到该文件中,即可实现所有控件的功能,实现思路见代码注释!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data.Odbc; //ODBC命名空间
-
- namespace ckgl.admin.wh
- {
- public partial class mmwh : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
-
- }
-
- protected void Button1_Click(object sender, EventArgs e)
- {
- if(TextBox1.Text==""||TextBox2.Text=="")
- {
- Response.Write("");
- return;
- }
- if (TextBox3.Text == "" || TextBox4.Text == "")
- {
- Response.Write("");
- return;
- }
- if (TextBox3.Text != TextBox4.Text )
- {
- Response.Write("");
- return;
- }
- OdbcConnection con = DB.Lianjie();
- con.Open();
- string sql1 = "select * from glyb where gno='" + TextBox1.Text + "' and gpass='" + TextBox2.Text + "' ";
- OdbcCommand mycommand1 = new OdbcCommand(sql1, con);
- OdbcDataReader sdr = mycommand1.ExecuteReader();
- if(sdr.Read())
- {
- string sql2 = " update glyb set gpass='" + TextBox3.Text + "' where gno='" + TextBox1.Text + "'";//根据用户输入的新密码修改密码
- OdbcCommand mycommand2 = new OdbcCommand(sql2, con);
- mycommand2.ExecuteNonQuery();
- Response.Write("");
- }
- else
- {
- Response.Write("");
- return;
- }
- con.Close();
- }
-
- protected void Button2_Click(object sender, EventArgs e)
- {
- TextBox1.Text = "";
- TextBox2.Text = "";
- TextBox3.Text = "";
- TextBox4.Text = "";
- }
- }
- }
在母版页【Site.Master】中添加相应的修改密码菜单,这一步博主偷懒一下罢~你一定会的!