版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、快速上手wap网站开发 近来工作比较紧张,一直想写一些东西,无奈没有时间,现在开发的市移动wap论坛终于告一段落,现在将开发过程简单记录一下,以备日后参考,都是一些简单的使用过程,可为初次接触wap开发的提供一点点参考,高手可以忽略。 开发工具:vs2008 模拟器:vs自带仿真管理器 framework版本:2.0一。配置环境: vs2008中已经没有了新建wap的选项,所需的wap模板需要从网上下载: 下载地址:
2、,这是我的网络硬盘,下载下来是一个ASPNETMobileTemplates.rar的文件,根据里面的说明将文件拷贝到所需的文件夹。 模拟器可用openware((官方免费注册下载地址)),也可用vs自带的设备仿真器(要先安装ActiveSync,),在工具设备仿真管理器选择pocket pc 2003中的pocket pc 2003 se仿真器右键点解连接,然后再右键点击插入底座,运行后即可使用,不过在仿真管理器中地址不要用local,要用本机ip地址。 二。建立数据库:
3、160; 数据库采用sqlserver,建立一个名为wapDB的数据库,如下图: 然后添加一个用户表userinfo,如下图: 为数据库添加一条记录,如下图:
4、60; 建立表document,用来存储发布的文章,表结构如下图: 先为document表添加20条数据,用来显示,如下图: 至此,数据库建立完毕,下面我们将采用vs2008来具体开发。 三。建立工程,开始开发: 首先,我们建立一个testWap的项目,如下图:
5、160; 将新建项目默任生成的default.aspx删除,新建一个login.aspx的mobile web form模板(在第一步环境配置中按照说明将ASPNETMobileTemplates.rar中的文件拷贝到各个文件夹后,就会在新建项目中最下面的模板中显示mobile模板了),如下图: 建立好以后,按照上述方法再添加一个index.aspx的文件。 至此,我们所需的文件已经全部建立完成,login.aspx
6、用来登录,登录后到index.aspx页面,此页面用来分页显示document文章表中的内容,并且可以添加文章记录。(注意,做好网页后,需要在记事本中将我们刚才建立的login.aspx、index.aspx打开重新保存一下,保存编码改为utf-8,覆盖原文件即可,这样做是因为项目采用utf-8编码,如果不这样的话,页面含有中文的话就会显示为乱码。),如下图: 然后开始编码,具体编码和中的编码过程一样,不同的就是换成了mobile控件,这里需要注意的vs下开发wap不支持可视化设计,我们只能在后台手工编码,当添
7、加<mobile>控件的时候,只要打上<m就会出现你所需要的mobile控件,mobile控件的具体有哪些和都有什么属性请参考其他文档,日后若有时间,我会将mobile控件的使用说明详细介绍一下,这里给大家引荐一个网址,这里面有mobile控件的介绍和使用说明,我们这里只用到了objectlist控件和textbox、textview控件以及command、Label控件,command控件其实就是button按钮,在mobile里叫command。 这里我们建立三个文件:
8、0; login.aspx:登录页面 index.aspx:分页显示文章页面,带有快速发表 view.aspx:显示文章具体内容页面三个页面源代码:login.aspx 前台代码具体如下: 1. <% Page Language="C#" AutoEventWireup=&quo
9、t;true" Inherits="testWap.login" Codebehind="login.aspx.cs" %>2. <% Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>3.4. <html xmlns=&qu
10、ot;/1999/xhtml" >5. <body>6.7. <mobile:Form id="Form1" runat="server"> <!-表单->8. <mobile:Label ID="z1" Runat="server" Font-Siz
11、e="Large" ForeColor="#3333cc">登录窗口</mobile:Label>9. <!-lbl_out:信息标签,初始隐藏,登录失败后或退出系统时显示信息->10. <mobile:Label ID="lbl_out" Runat="server" ForeColor=&quo
12、t;Red" Visible="false"></mobile:Label> 11. 用户名:<br />12. <mobile:TextBox ID="tb_User" Runat="server" Size="10" ></mobile:Tex
13、tBox><!-用户名输入框:tb_User->13. 密码:<br />14. <mobile:TextBox ID="tb_Pwd" Runat="server" Size="10" Password="True"></mobile:TextBox><!-密码输
14、入框:tb_Pwd->15.16. <mobile:Command ID="Button1" Runat="server" OnClick="Button1_OnClick" >登录</mobile:Command><!-登录按钮->17. </mobile:Form>18.19. </body>20. </html>21.login.aspx.c
15、s 后台代码具体如下:1. using System;2. using System.Collections;3. using System.ComponentModel;4. using System.Data;5. using System.Drawing;6. using System.Web;7. using System.Web.Mobile;8. using System.Web.SessionState;9. using System.Web.
16、UI;10. using System.Web.UI.MobileControls;11. using System.Web.UI.WebControls;12. using System.Web.UI.HtmlControls;13. using System.Data.SqlClient;14.15. namespace testWap16. 17. public partial class18. 19.
17、0; protected void Page_Load(object sender, EventArgs e)20. 21. #region 系统退出时将信息标签lbl_out赋值并且显示 22.
18、60; if (Session"loginOutInfo" != null)23. 24. string
19、160;outInfo = Session"loginOutInfo".ToString();25. this.lbl_out.Text = outInfo;26. &
20、#160;this.lbl_out.Visible = true;27. Session.Clear();28. 29.
21、 #endregion 30. 31.32. / <summary> 33. / 登录验证 34. / </summary> 35.
22、60; / <param name="sender"></param> 36. / <param name="e"></param> 37. protected void But
23、ton1_OnClick(object sender, EventArgs e)38. 39. string username = this.tb_User.Text.Trim();40. &
24、#160; string userpwd = this.tb_Pwd.Text.Trim();41. string strCon = "Data Source=(local);Database=wapDB;Uid=sa;Pwd=zxkj"42. &
25、#160; string strSql = "select * from userinfo where user_name='"+username+"' and user_pwd='"+userpwd+"'"43. SqlConn
26、ection conn = new SqlConnection(strCon);44. conn.Open();45. SqlDataAdapter da = new SqlDataAdapter(strSql, conn
27、);46. DataSet ds = new DataSet();47. da.Fill(ds);48. conn.Close(
28、);49.50. int rowCount = ds.Tables0.Rows.Count;51.52. if (rowCount > 0)53. &
29、#160; 54. Session"username" = ds.Tables0.Rows0"user_name".ToString().Trim();55.
30、; Response.Redirect("index.aspx");56. 57. else58. 59.
31、60; this.lbl_out.Text = "用户名密码错误,请重新登录!"60. this.lbl_out.Visible = true;61.
32、60; 62. 63. 64. index.aspx 前台代码具体如下:1. <% Page Language="C#" AutoEventWireup="true" Inherits="tes
33、tWap.index" Codebehind="index.aspx.cs" %>2. <% Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>3.4. <html xmlns="/1999/xhtml"
34、 >5. <body>6.7. <mobile:Form id="Form1" runat="server"> <!-表单->8. <mobile:Label ID="lbl_uname" Runat="server"></mobile:Label>9. <mobile:Label ID="wt" Runat=
35、"server" Font-Size="Large" ForeColor="Red">文章列表</mobile:Label>10. <mobile:ObjectList ID="ObjectList1" Runat="server"><!-ObjectList控件->11. <DeviceSpecific>12. <Choic
36、e>13. <ItemTemplate>14. <mobile:Link Runat="server" Text='<%# (ObjectListItem)Container)"doc_title" %>' NavigateUrl='<%# "view.aspx?id="+(ObjectListItem)Container)"do
37、c_id"%>' ID="Title" NAME="Title" Wrapping="Wrap">15. </mobile:Link>16. </ItemTemplate>17. </Choice>18. </DeviceSpecific>19. </mobile:ObjectLi
38、st>20. <br />21. <mobile:Label id="lbl_page" runat="server" Visible="False">1</mobile:Label><!-页码:lbl_page->22. <mobile:Label id="lbl_pagecount" runat="server" Visible="False"
39、>1</mobile:Label><!-总页数:lbl_pagecount->23. <mobile:Link ID="lnk_top" Runat="server" BreakAfter="False">首页 | </mobile:Link><mobile:Link id="lnk_pre" runat="server"> 上一页</mobil
40、e:Link>24. <mobile:Link id="lnk_end" runat="server" Visible="False" BreakAfter="false">尾页 | </mobile:Link><mobile:Link id="lnk_next" runat="server"> 下一页</mobile:Link>25
41、. <br />26. <mobile:Label id="lbl_fabu" Runat="server">发布文章:</mobile:Label>27. <mobile:Label ID="lbl_error" Runat="server" Visible="false" ForeColor="Red"></mobile:Label>28. &
42、lt;mobile:TextBox ID="tb_title" Runat="server"></mobile:TextBox>29. <mobile:TextBox ID="tb_content" Runat="server"></mobile:TextBox>30. <mobile:Command ID="Button2" Runat="server" O
43、nClick="Button2_OnClick" BreakAfter="false">发表</mobile:Command><mobile:Command ID="Button1" Runat="server" OnClick="Button1_OnClick">退出</mobile:Command>31. </mobile:Form>32.33. </body>34. </html
44、>index.aspx.cs 后台代码具体如下: 1. using System;2. using System.Collections;3. using System.ComponentModel;4. using System.Data;5. using System.Drawing;6. using System.Web;7. using System.Web.Mobile;8. using System.Web.SessionState;9.
45、using System.Web.UI;10. using System.Web.UI.MobileControls;11. using System.Web.UI.WebControls;12. using System.Web.UI.HtmlControls;13. using System.Data.SqlClient;14.15. namespace testWap16. 17. public partial class18.
46、0; 19. protected void Page_Load(object sender, EventArgs e)20. 21. if (Session"username"
47、; = null)22. 23. Session"loginOutInfo" = "登录时间到,请重新登录!"24.
48、60; Response.Redirect("login.aspx");25. 26. this.lbl_uname.Text = "欢迎您:&
49、quot;+(string)Session"username"27. if (Session"ok" != null)28. 29.
50、 this.lbl_error.Text = "发表成功!"30. this.lbl_error.Visible = true;31.
51、; Session"ok" = null;32. 33. if (!IsPostBack)34.
52、; 35. Bind();36. 37. 38.39.
53、60; private void Bind()40. 41. string rPage = Request.QueryString"Page"42.
54、; int page = 1;43. if (rPage != null)44. 45.
55、0; try46. 47. page = int.Parse(rPage);48.
56、60; 49. catch50. 51.
57、0; page = 1;52. 53. &
58、#160;54. Session"page" = page;55. PagedDataSource ps = new PagedDataSource();56.
59、; string strCon = "Data Source=(local);Database=wapDB;Uid=sa;Pwd=zxkj"57. string strSql = "select * from document order
60、0;by doc_id desc"58. SqlConnection conn = new SqlConnection(strCon);59. conn.Open();60.
61、60; SqlDataAdapter da = new SqlDataAdapter(strSql, conn);61. DataSet ds = new DataSet();62.
62、160; da.Fill(ds);63. conn.Close();64. ps.DataSource = ds.Tables0.DefaultView;65.
63、 ps.AllowPaging = true;66. ps.PageSize = 5;67. ps.CurrentPageIndex = page - 1;68.
64、; this.lnk_top.Visible = true;69. this.lnk_pre.Visible = true;70. this.lnk_next.Vis
65、ible = true;71. this.lnk_end.Visible = true;72. this.lnk_top.NavigateUrl = "index.aspx?page=1"73.
66、 this.lnk_pre.NavigateUrl = "index.aspx?page=" + (page - 1);74. this.lnk_next.NavigateUrl = "index.aspx?page="
67、;+ (page + 1);75. this.lnk_end.NavigateUrl = "index.aspx?page=" + ps.PageCount;76. if (page = 1)
68、77. 78. this.lnk_top.Visible = false;79.
69、60; this.lnk_pre.Visible = false;80. 81. if (page = ps.PageCount)82.
70、60; 83. this.lnk_next.Visible = false;84. this.lnk_end.Visible = false;
71、85. 86. if (ps.PageCount = 1)87. 88.
72、160; this.lnk_top.Visible = false;89. this.lnk_pre.Visible = false;90.
73、 this.lnk_next.Visible = false;91. this.lnk_end.Visible = false;92. 93.
74、 this.lbl_pagecount.Text = Convert.ToString(ps.PageCount);94. this.ObjectList1.DataSource = ps;95. &
75、#160; this.ObjectList1.DataBind();96. 97.98. protected void Button2_OnClick(object sender, EventArgs e)99. &
76、#160;100. string title = this.tb_title.Text.Trim();101. string content = this.tb_content.Text.Trim();102.
77、160; if (title = "" | title = null | content = "" | content = null)103. 104.
78、60; this.lbl_error.Text = "文章标题或内容不能为空!"105. this.lbl_error.Visible = true;106.
79、; return;107. 108. string strSql = "insert docum
80、ent values('" + title + "','" + content + "')"109. string strCon = "Data Source=(local);Database=wapDB;Uid=sa;Pwd=zxk
81、j"110. SqlConnection conn = new SqlConnection(strCon);111. conn.Open();112. &
82、#160; SqlCommand com = new SqlCommand(strSql, conn);113. com.ExecuteNonQuery();114. conn.Close();115.
83、 Session"ok" = "ok"116. Response.Redirect("index.aspx");117. 118.119.
84、; protected void Button1_OnClick(object sender, EventArgs e)120. 121. try122.
85、 123. Session.Clear();124. Session"loginOutInfo" = "退出成功!&qu
86、ot;125. 126. catch127. 128.
87、160; Session"loginOutInfo" = "退出成功!"129. 130. Response.Redirect("login.aspx");131
88、. 132. 133. view.aspx 前台代码具体如下: 1. <% Page Language="C#" AutoEventWireup="true" Inherits="testWap.view" Codebehind="view.aspx.cs"
89、160;%>2. <% Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>3.4. <html xmlns="/1999/xhtml" >5. <body>6. <mobile:Form id="Fo
90、rm1" runat="server">7. <mobile:Label ID="Label1" Runat="server" ForeColor="#0000cc" >帖子内容</mobile:Label>8. <mobile:Label ID="z1" Runat="server" ForeColor="#0066ff">
91、 标题:</mobile:Label>9. <mobile:TextView ID="tv_title" Runat="server" Wrapping="Wrap"></mobile:TextView>10. <mobile:Label ID="z2" Runat="server" ForeColor="#0066ff"> 内容:</mobi
92、le:Label>11. <mobile:TextView ID="tv_Content" Runat="server" Wrapping="Wrap"></mobile:TextView>12. <mobile:Link ID="lnk_FanHui" Runat="server" BreakAfter="false">返回上层</mobile:Link>
93、60;| 13. <mobile:Command ID="Command1" Runat="server" OnClick="Button1_OnClick">退出</mobile:Command>14. </mobile:Form>15. </body>16. </html>view.aspx.cs 后台代码具体如下:1. using System;2. using
94、System.Collections;3. using System.ComponentModel;4. using System.Data;5. using System.Drawing;6. using System.Web;7. using System.Web.Mobile;8. using System.Web.SessionState;9. using System.Web.UI;10. using System.Web.UI.MobileControls;11. using System.W
95、eb.UI.WebControls;12. using System.Web.UI.HtmlControls;13. using System.Data.SqlClient;14.15. namespace testWap16. 17. public partial class18. 19. protected void Page_Lo
96、ad(object sender, EventArgs e)20. 21. if (Session"username" = null | Session"page" = null)22.
97、0; 23. Session"loginOutInfo" = "登录时间到,请重新登录!"24.
98、 Response.Redirect("login.aspx");25. 26. int docid = int.Parse(Request"id".ToString();27.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年菏泽市第三人民医院公开招聘合同制工作人员(30人)笔试考试备考试题及答案解析
- 2025-2026贵州贵阳市观山湖区逸都国际学校招聘临聘教师4人考试笔试备考试题及答案解析
- 2025福建厦门市集美区顶许小学顶岗教师招聘4人笔试考试参考题库及答案解析
- 信号设备制造钳工改进知识考核试卷含答案
- 蓄电池充电工班组建设知识考核试卷含答案
- 配料熔制工班组协作考核试卷含答案
- 手工平毯工安全技能模拟考核试卷含答案
- 2025呼和浩特春华水务开发集团招聘84名工作人员考试笔试参考题库附答案解析
- 2026广东深圳市事业单位集中招聘高校毕业生658人笔试考试备考题库及答案解析
- 2025山东晨鸣集团生产岗位专项招聘笔试考试参考题库及答案解析
- (2025年标准)sm调教协议书
- 中学作业管理制度及监督执行方案
- 超高压果汁制备-洞察及研究
- 医院儿科简介
- 2025年照护师初级考试题库
- 2025年年产10万吨饮料生产线新建建设项目可行性研究报告
- 人工智能学习汇报
- 二维半导体材料及其异质结:生长、性能与光电子应用的深度剖析
- 部编版道德与法治小学五年级上册全册教学设计+教学计划进度
- 教师秋季远足活动方案
- 2025年中国葡萄酒行业市场供需格局及行业前景展望报告
评论
0/150
提交评论