asp.net 图片按钮单击事件定义如下,可是单击它的时候却是页面重载,没有办法修改密码。。。
//“修改”按钮单击事件protectedvoidmodifypwd_Click(objectsender,System.Web.UI.ImageClickEventAr...
// “修改”按钮单击事件
protected void modifypwd_Click(object sender,System.Web.UI.ImageClickEventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["netexamConnectionString"].ToString()); //创建连接对象
string SelectSql="select * from Student where SId ='"+Session["ID"].ToString()+"'and SPwd='"+txtoldpwd.Text.Trim()+"'";
string UpdateSql="update Student set userPwd='"+txtnewpwd.Text.Trim()+"' where SId='"+Session["ID"].ToString()+"'";
SqlCommand selectcmd = new SqlCommand(SelectSql, conn); //根据用户名和输入的旧密码查询用户
try
{
conn.Open(); //打开连接
SqlDataReader sdr = selectcmd.ExecuteReader(); //把查询到的结果复制给sdr
if (sdr.Read()) //如果输入旧密码正确,进行修改密码
{
sdr.Close();
SqlCommand updatecmd = new SqlCommand(UpdateSql, conn);
int i = updatecmd.ExecuteNonQuery(); //SQL语句后返回受影响的行数
if (i > 0)
{
Response.Write("<script language='javascript'>alert('成功修改密码!')</script>");
}
else
{
Response.Write("<script language='javascript'>alert('修改密码失败!')</script>");
}
}
else // 如果输入的旧密码错误,提示错误信息
{
Response.Write("<script language='javascript'>alert('您输入的密码错误,检查后重新输入!')</script>");
}
}
catch (System.Exception ee)
{
Response.Write("<script language=javascript>alert('" + ee.Message.ToString() + "')</script>");
}
finally
{
conn.Close(); // 关闭连接
}
} 展开
protected void modifypwd_Click(object sender,System.Web.UI.ImageClickEventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["netexamConnectionString"].ToString()); //创建连接对象
string SelectSql="select * from Student where SId ='"+Session["ID"].ToString()+"'and SPwd='"+txtoldpwd.Text.Trim()+"'";
string UpdateSql="update Student set userPwd='"+txtnewpwd.Text.Trim()+"' where SId='"+Session["ID"].ToString()+"'";
SqlCommand selectcmd = new SqlCommand(SelectSql, conn); //根据用户名和输入的旧密码查询用户
try
{
conn.Open(); //打开连接
SqlDataReader sdr = selectcmd.ExecuteReader(); //把查询到的结果复制给sdr
if (sdr.Read()) //如果输入旧密码正确,进行修改密码
{
sdr.Close();
SqlCommand updatecmd = new SqlCommand(UpdateSql, conn);
int i = updatecmd.ExecuteNonQuery(); //SQL语句后返回受影响的行数
if (i > 0)
{
Response.Write("<script language='javascript'>alert('成功修改密码!')</script>");
}
else
{
Response.Write("<script language='javascript'>alert('修改密码失败!')</script>");
}
}
else // 如果输入的旧密码错误,提示错误信息
{
Response.Write("<script language='javascript'>alert('您输入的密码错误,检查后重新输入!')</script>");
}
}
catch (System.Exception ee)
{
Response.Write("<script language=javascript>alert('" + ee.Message.ToString() + "')</script>");
}
finally
{
conn.Close(); // 关闭连接
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询