实验四采用页面切换与导航技术完成网页设计.docx
《实验四采用页面切换与导航技术完成网页设计.docx》由会员分享,可在线阅读,更多相关《实验四采用页面切换与导航技术完成网页设计.docx(11页珍藏版)》请在冰点文库上搜索。
![实验四采用页面切换与导航技术完成网页设计.docx](https://file1.bingdoc.com/fileroot1/2023-6/6/7ac1295d-4b5c-4822-aaca-09aa548d22bd/7ac1295d-4b5c-4822-aaca-09aa548d22bd1.gif)
实验四采用页面切换与导航技术完成网页设计
实验报告
课程名称
Web程序设计
实验名称
实验四、采用页面切换与导航技术完成网页设计
日期
2014.3.31
学生学号
姓名
班级
实验目的:
1.熟悉网页切换和导航的常用方法。
2.掌握利用按钮的PostbackUrl属性、Response.Redirect和Server.Transfer方法实现页面切换和数据传递。
3.掌握SiteMapPath、Menu、TreeView控件的应用。
实验条件:
电脑一台、能上网查阅资料。
实验内容与步骤:
1.创建网站“Exp5”
2.创建一个Login网页,在页面中输入用户名和密码,点击“登录”按钮利用PostBackUrl属性提交到Main页面,在Main页面中判断用户和密码的合法性,合法时显示“欢迎【用户名】”内容,否则用Redirect转回到Login网页。
思考:
如何在Main页面中获得Login页面传递的用户名和密码。
3.创建三个页面page1、page2、page3,在Main页面中分别利用Button、LinkButton和ImageButton控件的PostbackUrl属性实现从Main页切换到这3个网页。
4.创建2个网页page4和page5,从Page1利用QueryString传递数据到Page4,从Page2利用Session传递数据到Page5。
5.在Main、page1~page5网页中利用SiteMapPath控件进行导航。
6.在Main网页中利用Menu、TreeView控件实现导航。
源代码
题目一:
图1创建网站
题目二:
图2login
图2.1Main
Login.cs:
publicpartialclassexp4_1_Login:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
}
publicstringGetText1
{
get{returnTextBox1.Text;}
}
}
Main.cs:
(在Main源视图中添加以下信息:
<%@PreviousPageTypeVirtualPath="~/exp4/2/Login.aspx"%>
)
publicpartialclassexp4_1_Main:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
if(PreviousPage!
=null)
{
if(String.IsNullOrEmpty(PreviousPage.GetText1))
{
Response.Write("格式有误");
}
else
{
Response.Write("欢迎:
"+PreviousPage.GetText1);
}
}
}
}
题目三:
图3.13个控件的导航
图3.2button导航
图3.3Linkbutton导航
图3.4Image导航
题目四:
图4.1Query传递
图4.2接收Query
图4.3session传递
图4.4接收session
Page1.cs:
publicpartialclassexp4_3_page1:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
Response.Write("欢迎来到page1");
Response.Write("
");
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
Server.Transfer(string.Format("~/exp4/4/page4.aspx?
文字={0}",Server.UrlEncode(TextBox1.Text)));
}
}
Page2.cs:
publicpartialclassexp4_3_page2:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
Response.Write("欢迎来到page2");
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
Session["text1"]=TextBox1.Text;
Response.Redirect("~/exp4/4/page5.aspx");
}
}
Page3.cs:
publicpartialclassexp4_3_page3:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
Response.Write("欢迎来到page3");
}
}
题目五:
图5.1page1
图5.2page2
图5.3page3
图5.4page4
图5.5page5
在根目录新建一个sitemap文件,主要代码如下:
xmlversion="1.0"encoding="utf-8"?
>
题目六:
图6.1menu和treeview导航
图6.2menu导航
图6.3treeview导航
实验总结(结论或问题分析):
通过本次实验,我在上机过程中遇到了不少的难题,例如不懂得如何编排网页的格式,怎样调用功能语句,怎样实行调试。
经过这次实验,使我深深的认识到自己水平的不足,学习web开发不仅要认真听课,更要多上机联系。
最后在老师和同学们的帮助下,基本完成了这次实验。
加深了我对这门课的了解。
实验成绩
任课教师签名
郭俊恩