aspnet题库 联系客服

发布时间 : 星期日 文章aspnet题库更新完毕开始阅读46564f39e2bd960590c677cb

现,使用javascript可以实现在跳转之前做其他同样的javascript代码编写的操作,而使用redirect不行。

13.若给textbox添加TextChanged事件代码,代码并不运行,最可能的原因是什么? 答:AutoPostBack属性默认为false,要手动设置为true

14.能否将html中的table的一行变成可编程的服务器控件,如何实现?

答:可以,直接在标签内加一个runat=”server”和一个id属性,变成服务器控件即可。

15.简述如何实现页面传值。

答:跳转的url中加上页面传值变量并赋值,如需多个变量,中间用’&’隔开;并在跳转后的用Request.QueryString来获取传值变量。 16.简述一般情况下,用户登录系统的步骤。

答:首先验证用户名和密码,之后写入Session保存当前登录用户信息,最后实现页面跳转。

程序设计题 2道

1、在page_load函数中编写代码,测试Session[“userName”]是否为空,若为空则跳转到登陆页面login.aspx,不为空则将Session[“userName”]的值赋给string 变量u_name,其中u_name已定义。 string u_name;

protected void Page_Load(object sender, EventArgs e) {

if(Session[“userName”] == null)

response.redirect(“login.aspx”); else

u_name = Session[“username”].ToString() }

2、下图为一登陆界面,现要求编写代码实现若用户名或密码后的textBox为空,则弹出提示框,提示框的内容自定,用户名后的textbox控件ID为txt_userName,密码后的textbox控件ID为txt_pwd。

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 == “”)

Response.Write(“”); if(user_pwd == “”)

Response.Write(“”); }

3、设计一个登录界面如图,现要实现登录按钮的单击事件,单击按钮时,读取用户输入的用户名,密码,并判断用户名密码是否为有效用户名“ahead”和密码“12345”。如果登录

成功将用户名保存到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; }