成功将用户名保存到session中,并跳转到主页index.aspx。请完成按钮单击事件。
注:用户名后的textbox控件ID为txt_userName,密码后的textbox控件ID为txt_pwd,写入session对象中的变量名为userName。
protected void Button1_Click(object sender, EventArgs e) {
String user_name = txt_userName.Text.trim(); String user_pwd = txt_pwd.Text.trim();
If(user_name == “ahead” && user_pwd == “12345”) {
Response.Redirect(“index.aspx”); Session[“userName”] = “ahead”;
} }
4、编程实现页面传值。点击按钮btn_jump从A.aspx跳转到B.aspx页面,并且把A.aspx页面的两个值u_id和u_name传送到B.aspx页面,并写代码在B.aspx的Page_Load函数中用user_id和user_name两个变量接收。假设页面A.aspx中的u_id和u_name两个变量已有值可直接使用,页面B.aspx中的user_id和user_name已定义,且为全局变量。 A.aspx中:
protected void btn_jump_Click(object sender, EventArgs e) {
String url = “B.aspx?u_id=” + u_id + “&u_name=” + u_name; Response.Redirect(url); }
B.aspx中:
string user_id,user_name;
protected void Page_Load(object sender, EventArgs e) {
user_id = Request.QueryString[“u_id”]; user_name = Request.QueryString[“u_name”]; }
5、设表user_info有字段user_id(字符型),user_name(字符型),user_dep(整型);表dep有字段dep_id(整型),dep_name(字符型);请写出SQL语句,求user_id为”liping”的人的姓名(user_name)和所在部门名称(dep_name)。
Select user_name dep_name from dep, user_info where user_id=’liping’ and user_dep=dep_id
6、界面如下图所示,请用javascript编写代码实现若用户名或密码后的textBox为空,则弹出提示框,提示框的内容自定,用户名后的textbox控件ID为txt_userName,密码后的
textbox控件ID为txt_pwd。
function() {
Var user_name = document.GetElementByid(‘txt_userName’); Var user_pwd = document.GetElementByid(‘txt_pwd);
if( user_name == “”) {
Alert(“用户名不能为空”); Return false; }
if( user_pwd == “”) {
Alert(“密码不能为空”); Return false; }
Return true; }