版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、快速上手wap網(wǎng)站開發(fā) 近來工作比較緊張,一直想寫一些東西,無奈沒有時間,現(xiàn)在開發(fā)的市移動wap論壇終于告一段落,現(xiàn)在將開發(fā)過程簡單記錄一下,以備日后參考,都是一些簡單的使用過程,可為初次接觸wap開發(fā)的提供一點點參考,高手可以忽略。 開發(fā)工具:vs2008 模擬器:vs自帶仿真管理器 framework版本:2.0一。配置環(huán)境: vs2008中已經(jīng)沒有了新建wap的選項,所需的wap模板需要從網(wǎng)上下載: 下載地址:
2、,這是我的網(wǎng)絡硬盤,下載下來是一個ASPNETMobileTemplates.rar的文件,根據(jù)里面的說明將文件拷貝到所需的文件夾。 模擬器可用openware((官方免費注冊下載地址)),也可用vs自帶的設備仿真器(要先安裝ActiveSync,),在工具設備仿真管理器選擇pocket pc 2003中的pocket pc 2003 se仿真器右鍵點解連接,然后再右鍵點擊插入底座,運行后即可使用,不過在仿真管理器中地址不要用local,要用本機ip地址。 二。建立數(shù)據(jù)庫:
3、160; 數(shù)據(jù)庫采用sqlserver,建立一個名為wapDB的數(shù)據(jù)庫,如下圖: 然后添加一個用戶表userinfo,如下圖: 為數(shù)據(jù)庫添加一條記錄,如下圖:
4、60; 建立表document,用來存儲發(fā)布的文章,表結構如下圖: 先為document表添加20條數(shù)據(jù),用來顯示,如下圖: 至此,數(shù)據(jù)庫建立完畢,下面我們將采用vs2008來具體開發(fā)。 三。建立工程,開始開發(fā): 首先,我們建立一個testWap的項目,如下圖:
5、160; 將新建項目默任生成的default.aspx刪除,新建一個login.aspx的mobile web form模板(在第一步環(huán)境配置中按照說明將ASPNETMobileTemplates.rar中的文件拷貝到各個文件夾后,就會在新建項目中最下面的模板中顯示mobile模板了),如下圖: 建立好以后,按照上述方法再添加一個index.aspx的文件。 至此,我們所需的文件已經(jīng)全部建立完成,login.aspx
6、用來登錄,登錄后到index.aspx頁面,此頁面用來分頁顯示document文章表中的內容,并且可以添加文章記錄。(注意,做好網(wǎng)頁后,需要在記事本中將我們剛才建立的login.aspx、index.aspx打開重新保存一下,保存編碼改為utf-8,覆蓋原文件即可,這樣做是因為項目采用utf-8編碼,如果不這樣的話,頁面含有中文的話就會顯示為亂碼。),如下圖: 然后開始編碼,具體編碼和中的編碼過程一樣,不同的就是換成了mobile控件,這里需要注意的vs下開發(fā)wap不支持可視化設計,我們只能在后臺手工編碼,當添
7、加<mobile>控件的時候,只要打上<m就會出現(xiàn)你所需要的mobile控件,mobile控件的具體有哪些和都有什么屬性請參考其他文檔,日后若有時間,我會將mobile控件的使用說明詳細介紹一下,這里給大家引薦一個網(wǎng)址,這里面有mobile控件的介紹和使用說明,我們這里只用到了objectlist控件和textbox、textview控件以及command、Label控件,command控件其實就是button按鈕,在mobile里叫command。 這里我們建立三個文件:
8、0; login.aspx:登錄頁面 index.aspx:分頁顯示文章頁面,帶有快速發(fā)表 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:信息標簽,初始隱藏,登錄失敗后或退出系統(tǒng)時顯示信息->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 系統(tǒng)退出時將信息標簽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><!-總頁數(shù):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">發(fā)布文章:</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">發(fā)表</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 = "發(fā)表成功!"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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 煤層氣預處理值班員發(fā)展趨勢能力考核試卷含答案
- 稀土化工操作工成果轉化強化考核試卷含答案
- 農(nóng)機修理工安全生產(chǎn)規(guī)范測試考核試卷含答案
- 燒結球團原料工安全實操評優(yōu)考核試卷含答案
- 育嬰員崗前實踐理論考核試卷含答案
- 脫硫脫硝處理工風險識別測試考核試卷含答案
- 制球工崗前環(huán)保及安全考核試卷含答案
- 車輛質保合同范本
- 采購框架協(xié)議合同
- 采購委外合同范本
- 礦山安裝施工方案
- 貿易安全知識培訓內容課件
- 2026屆上海市寶山區(qū)吳淞中學化學高一上期中統(tǒng)考模擬試題含解析
- 《反恐怖主義法》培訓測試題及答案
- 律所報銷管理辦法
- 2024年瀏陽市社區(qū)工作者招聘真題
- IPC7530A2017GuidelinesTemperatureProfilingMassSolderingProcessesReflowWave(IPC-7530A 2017 回流焊和波峰焊工藝溫度曲線指南)
- 智能儲能系統(tǒng)的自適應電壓控制策略研究
- 車輛維修和保養(yǎng)服務方案投標文件(技術方案)
- JG/T 127-2017建筑門窗五金件滑撐
- T/TMAC 013-2019城市軌道交通站臺門檢測技術規(guī)范
評論
0/150
提交評論