




已阅读5页,还剩7页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
快速上手wap网站开发 近来工作比较紧张,一直想写一些东西,无奈没有时间,现在开发的市移动wap论坛终于告一段落,现在将开发过程简单记录一下,以备日后参考,都是一些简单的使用过程,可为初次接触wap开发的提供一点点参考,高手可以忽略。 开发工具:vs2008 模拟器:vs自带仿真管理器 framework版本:2.0一。配置环境: vs2008中已经没有了新建wap的选项,所需的wap模板需要从网上下载: 下载地址:/filebox/down/fc/911fb64660cbf75f42146ac021d642fe,这是我的网络硬盘,下载下来是一个ASPNETMobileTemplates.rar的文件,根据里面的说明将文件拷贝到所需的文件夹。 模拟器可用openware((官方免费注册下载地址)/dvl/tools_and_sdk/phone_simulator/),也可用vs自带的设备仿真器(要先安装ActiveSync,),在工具设备仿真管理器选择pocket pc 2003中的pocket pc 2003 se仿真器右键点解连接,然后再右键点击插入底座,运行后即可使用,不过在仿真管理器中地址不要用local,要用本机ip地址。二。建立数据库: 数据库采用sqlserver,建立一个名为wapDB的数据库,如下图: 然后添加一个用户表userinfo,如下图: 为数据库添加一条记录,如下图: 建立表document,用来存储发布的文章,表结构如下图: 先为document表添加20条数据,用来显示,如下图: 至此,数据库建立完毕,下面我们将采用vs2008来具体开发。三。建立工程,开始开发: 首先,我们建立一个testWap的项目,如下图: 将新建项目默任生成的default.aspx删除,新建一个login.aspx的mobile web form模板(在第一步环境配置中按照说明将ASPNETMobileTemplates.rar中的文件拷贝到各个文件夹后,就会在新建项目中最下面的模板中显示mobile模板了),如下图: 建立好以后,按照上述方法再添加一个index.aspx的文件。 至此,我们所需的文件已经全部建立完成,login.aspx用来登录,登录后到index.aspx页面,此页面用来分页显示document文章表中的内容,并且可以添加文章记录。(注意,做好网页后,需要在记事本中将我们刚才建立的login.aspx、index.aspx打开重新保存一下,保存编码改为utf-8,覆盖原文件即可,这样做是因为项目采用utf-8编码,如果不这样的话,页面含有中文的话就会显示为乱码。),如下图: 然后开始编码,具体编码和中的编码过程一样,不同的就是换成了mobile控件,这里需要注意的vs下开发wap不支持可视化设计,我们只能在后台手工编码,当添加控件的时候,只要打上m就会出现你所需要的mobile控件,mobile控件的具体有哪些和都有什么属性请参考其他文档,日后若有时间,我会将mobile控件的使用说明详细介绍一下,这里给大家引荐一个网址,这里面有mobile控件的介绍和使用说明,/article/aspnet-wap/Article_005_3.html我们这里只用到了objectlist控件和textbox、textview控件以及command、Label控件,command控件其实就是button按钮,在mobile里叫command。 这里我们建立三个文件: login.aspx:登录页面 index.aspx:分页显示文章页面,带有快速发表 view.aspx:显示文章具体内容页面三个页面源代码:login.aspx 前台代码具体如下:1. 2. 3.4. 5. 6.7. 8. 登录窗口9. 10. 11. 用户名:12. 13. 密码:14. 15.16. 登录17. 18.19. 20. 21.login.aspx.cs 后台代码具体如下:1. usingSystem;2. usingSystem.Collections;3. usingSystem.ComponentModel;4. usingSystem.Data;5. usingSystem.Drawing;6. usingSystem.Web;7. usingSystem.Web.Mobile;8. usingSystem.Web.SessionState;9. usingSystem.Web.UI;10. usingSystem.Web.UI.MobileControls;11. usingSystem.Web.UI.WebControls;12. usingSystem.Web.UI.HtmlControls;13. usingSystem.Data.SqlClient;14.15. namespacetestWap16. 17. publicpartialclasslogin:System.Web.UI.MobileControls.MobilePage18. 19. protectedvoidPage_Load(objectsender,EventArgse)20. 21. #region系统退出时将信息标签lbl_out赋值并且显示 22. if(SessionloginOutInfo!=null)23. 24. stringoutInfo=SessionloginOutInfo.ToString();25. this.lbl_out.Text=outInfo;26. this.lbl_out.Visible=true;27. Session.Clear();28. 29. #endregion 30. 31.32. / 33. /登录验证 34. / 35. / 36. / 37. protectedvoidButton1_OnClick(objectsender,EventArgse)38. 39. stringusername=this.tb_User.Text.Trim();40. stringuserpwd=this.tb_Pwd.Text.Trim();41. stringstrCon=DataSource=(local);Database=wapDB;Uid=sa;Pwd=zxkj;42. stringstrSql=select*fromuserinfowhereuser_name=+username+anduser_pwd=+userpwd+;43. SqlConnectionconn=newSqlConnection(strCon);44. conn.Open();45. SqlDataAdapterda=newSqlDataAdapter(strSql,conn);46. DataSetds=newDataSet();47. da.Fill(ds);48. conn.Close();49.50. introwCount=ds.Tables0.Rows.Count;51.52. if(rowCount0)53. 54. Sessionusername=ds.Tables0.Rows0user_name.ToString().Trim();55. Response.Redirect(index.aspx);56. 57. else58. 59. this.lbl_out.Text=用户名密码错误,请重新登录!;60. this.lbl_out.Visible=true;61. 62. 63. 64. index.aspx 前台代码具体如下:1. 2. 3.4. 5. 6.7. 8. 9. 文章列表10. 11. 12. 13. 14. mobile:LinkRunat=serverText=NavigateUrl=ID=TitleNAME=TitleWrapping=Wrap15. 16. 17. 18. 19. 20. 21. 122. 123. 首页|上一页24. 尾页|下一页25. 26. 发布文章:27. 28. 29. 30. 发表退出31. 32.33. 34. index.aspx.cs 后台代码具体如下:1. usingSystem;2. usingSystem.Collections;3. usingSystem.ComponentModel;4. usingSystem.Data;5. usingSystem.Drawing;6. usingSystem.Web;7. usingSystem.Web.Mobile;8. usingSystem.Web.SessionState;9. usingSystem.Web.UI;10. usingSystem.Web.UI.MobileControls;11. usingSystem.Web.UI.WebControls;12. usingSystem.Web.UI.HtmlControls;13. usingSystem.Data.SqlClient;14.15. namespacetestWap16. 17. publicpartialclassindex:System.Web.UI.MobileControls.MobilePage18. 19. protectedvoidPage_Load(objectsender,EventArgse)20. 21. if(Sessionusername=null)22. 23. SessionloginOutInfo=登录时间到,请重新登录!;24. Response.Redirect(login.aspx);25. 26. this.lbl_uname.Text=欢迎您:+(string)Sessionusername;27. if(Sessionok!=null)28. 29. this.lbl_error.Text=发表成功!;30. this.lbl_error.Visible=true;31. Sessionok=null;32. 33. if(!IsPostBack)34. 35. Bind();36. 37. 38.39. privatevoidBind()40. 41. stringrPage=Request.QueryStringPage;42. intpage=1;43. if(rPage!=null)44. 45. try46. 47. page=int.Parse(rPage);48. 49. catch50. 51. page=1;52. 53. 54. Sessionpage=page;55. PagedDataSourceps=newPagedDataSource();56. stringstrCon=DataSource=(local);Database=wapDB;Uid=sa;Pwd=zxkj;57. stringstrSql=select*fromdocumentorderbydoc_iddesc;58. SqlConnectionconn=newSqlConnection(strCon);59. conn.Open();60. SqlDataAdapterda=newSqlDataAdapter(strSql,conn);61. DataSetds=newDataSet();62. da.Fill(ds);63. conn.Close();64. ps.DataSource=ds.Tables0.DefaultView;65. ps.AllowPaging=true;66. ps.PageSize=5;67. ps.CurrentPageIndex=page-1;68. this.lnk_top.Visible=true;69. this.lnk_pre.Visible=true;70. this.lnk_next.Visible=true;71. this.lnk_end.Visible=true;72. this.lnk_top.NavigateUrl=index.aspx?page=1;73. this.lnk_pre.NavigateUrl=index.aspx?page=+(page-1);74. this.lnk_next.NavigateUrl=index.aspx?page=+(page+1);75. this.lnk_end.NavigateUrl=index.aspx?page=+ps.PageCount;76. if(page=1)77. 78. this.lnk_top.Visible=false;79. this.lnk_pre.Visible=false;80. 81. if(page=ps.PageCount)82. 83. this.lnk_next.Visible=false;84. this.lnk_end.Visible=false;85. 86. if(ps.PageCount=1)87. 88. this.lnk_top.Visible=false;89. this.lnk_pre.Visible=false;90. this.lnk_next.Visible=false;91. this.lnk_end.Visible=false;92. 93. this.lbl_pagecount.Text=Convert.ToString(ps.PageCount);94. this.ObjectList1.DataSource=ps;95. this.ObjectList1.DataBind();96. 97.98. protectedvoidButton2_OnClick(objectsender,EventArgse)99. 100. stringtitle=this.tb_title.Text.Trim();101. stringcontent=this.tb_content.Text.Trim();102. if(title=|title=null|content=|content=null)103. 104. this.lbl_error.Text=文章标题或内容不能为空!;105. this.lbl_error.Visible=true;106. return;107. 108. stringstrSql=insertdocumentvalues(+title+,+content+);109. stringstrCon=DataSource=(local);Database=wapDB;Uid=sa;Pwd=zxkj;110. SqlConnectionconn=newSqlConnection(strCon);111. conn.Open();112. SqlCommandcom=newSqlCommand(strSql,conn);113. com.ExecuteNonQuery();114. conn.Close();115. Sessionok=ok;116. Response.Redirect(index.aspx);117. 118.119. protectedvoidButton1_OnClick(objectsender,EventArgse)120. 121. try122. 123. Session.Clear();124. SessionloginOutInfo=退出成功!;125. 126. catch127. 128. SessionloginOutInfo=退出成功!;129. 130. Response.Redirect(login.aspx);131. 132. 133. view.aspx 前台代码具体如下:1. 2. 3.4. 5. 6. 7. 帖子内容8. 标题:9. 10. 内容:11. 12. 返回上层|13. 退出14. 15. 16. view.aspx.cs 后台代码具体如下:1. usingSystem;2. usingSystem.Collections;3. usingSystem.ComponentModel;4. usingSystem.Data;5. usingSystem.Drawing;6. usingSystem.Web;7. usingSystem.Web.Mobile;8. usingSystem.Web.SessionState;9. usingSystem.Web.UI;10. usingSystem.Web.UI.MobileControls;11. usingSystem.Web.UI.WebControls;12. usingSystem.Web.UI.HtmlControls;13. usingSystem.Data.SqlClient;14.15. namespacetestWap16. 17. publicpartialclassview:System.Web.UI.MobileControls.MobilePage18. 19. protectedvoidPage_Load(objectsender,EventArgse)20. 21. if(Sessionusername=null|Sessionpage=null)22. 23. SessionloginOutInfo=登录时间到,请重新登录!;24. Response.Redirect(login.aspx);25. 26. intdocid=int.Parse(Requestid.ToString();27. stringstrCon=DataSource=(local);Database=wapDB;Uid=sa;Pwd=zxkj;28. stringstrSql=select*fromdocumentwh
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年速冻丸类制品合作协议书
- 智慧城市发展背景下智能交通系统的战略规划
- 2025年紫外固化材料项目发展计划
- 创新教育心理学方法激发学生内在动力
- 情绪心理学与课堂氛围的营造
- 医疗培训中的教育政策与效果评估研究
- 以数据为支撑的学生行为心理分析实践
- 在线教育在商业领域的广泛应用及未来前景
- 混合式学习模式在医学教学中的实践应用研究
- 中职教育课件
- 2025年上半年西安交通投资集团限公司招聘29人易考易错模拟试题(共500题)试卷后附参考答案
- 奶茶店转让合同书
- 2025年军转干考试全真模拟题库及答案(共三套)
- 供应商评鉴管理办法课件
- 青少年暑期安全知识课件
- 劳动与社会保障题库(含答案)
- GB/T 4074.7-2024绕组线试验方法第7部分:测定漆包绕组线温度指数的试验方法
- 蓝色医疗肝硬化腹水病人的护理
- 床护栏市场需求与消费特点分析
- 幕墙工程施工方案
- 2024秋期国家开放大学本科《合同法》一平台在线形考(任务1至4)试题及答案
评论
0/150
提交评论