快速上手wap網(wǎng)站開發(fā)_第1頁
快速上手wap網(wǎng)站開發(fā)_第2頁
快速上手wap網(wǎng)站開發(fā)_第3頁
快速上手wap網(wǎng)站開發(fā)_第4頁
快速上手wap網(wǎng)站開發(fā)_第5頁
已閱讀5頁,還剩14頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、wap論壇終于告一段落,現(xiàn)在將開 wap開發(fā)的提供一點點參考,快速上手wap網(wǎng)站開發(fā)近來工作比較緊張,一直想寫一些東西,無奈沒有時間,現(xiàn)在開發(fā)的市移動 發(fā)過程簡單記錄一下,以備日后參考,都是一些簡單的使用過程,可為初次接觸 咼手可以忽略。開發(fā)工具:vs2008模擬器:vs自帶仿真管理器framework版本:2.0一。配置環(huán)境:VS2008中已經(jīng)沒有了新建 wap的選項,所需的 wap模板需要從網(wǎng)上下載:,這是我的 網(wǎng)絡(luò)硬盤,下載下來是一個 ASP NETMobileTe mpl ates.rar 的文件,根據(jù)里面的說明將文件拷貝到所需的文件夾。下載地址:htt P: / n/fc/911fb

2、64660cbf75f42146ac021d642fe模擬器可用open ware(官方免費注冊下載地址)htt p:/develo per.o pen nd_sdk/ phon e_simulator/(要先安裝 ActiveSync ,),在工具一設(shè)備仿真管理器一選擇 器一右鍵點解連接,然后再右鍵點擊插入底座,運行后即可使用, 用本機ip地址。),也可用vs自帶的設(shè)備仿真器pocket pc 2003 中的 pocket pc 2003 se 仿真不過在仿真管理器中地址不要用local,要二。建立數(shù)據(jù)庫:數(shù)據(jù)庫采用sqlserver ,建立一個名為 wapDB的數(shù)據(jù)庫,如下圖:常規(guī)I數(shù)據(jù)文

3、件1爭務(wù)a志(S 名稱tai:lapDE 數(shù)搖庫然后添加一個用戶表useri nfo ,如下圖:列名1數(shù)據(jù)類型1檜陰1允許空gt J iITlI4亠n卻電eh遼50ustrjvrdchar50VLisar_kiLaniechai50Z為數(shù)據(jù)庫添加一條記錄,如下圖:user i A1nAinauser pwi1 user cname1_admin超級管理員列名1數(shù)據(jù)類型1 KS 1允許空eloc_i JLitt4doG-ti tienchar10/dac_contentnt ext16T先為document表添加20條數(shù)據(jù),用來顯示,如下圖:Aim idio(? titledoc c “nt電T

4、itniI ! I -O L lE34CJeTIGQllllll 1 1112 2 1-2345 & 739臉;煽魅蠟;驗;in 臉;s:3;3;3;2;s:s;3;si 驗?zāi)楤J 丄町-Lt - LH - 一1-Lf -Lfl -L4 i 丄f 一 丄 ZH - -LB IIf 丄三-Lt 試試試試試試謚試試試試試試試試試試?謚試試試驗1內(nèi)容親悻親隊親蓿.親椽親椽親隊親客親味 親肓F 親寄愛情、愛樂愛跟愛銀愛眾愛#、愛際 愛輙 愛常、愛銀 琵唐、友曰M押Ml怎雀復(fù)(d林!XI至此,數(shù)據(jù)庫建立完畢,下面我們將采用VS2008來具體開發(fā)。三。建立工程,開始開發(fā):首先,我們建立一個testWaP的

5、項目,如下圖:名稱:teslA/Vap位瓷心:解決方秦若稱(曲Itesmap將新建項目默任生成的default.aspx刪除,新建一個login.aspx 的mobile web form 模板(在第一步環(huán)境配置中按照說明將ASP NETMobileTe mpl ates.rar中的文件拷貝到各個文件夾后,就會在新建項目中最下面的模板中顯示 mobile模板了),如下圖:喬?W淞-teslwap関如!E=Visual C#外購件立弗文件WdWirxbvw For WPF 第姚IX4序應(yīng)用n摩渚敷WkFlw-iJWetnoble WsbrtODn WwCmfigura 即ForMLbrCoMrc

6、lAPcwmF育由粗li(超中flisJ若椒圈:仁 Mdl iZTiji建立好以后,按照上述方法再添加一個in dex.as px 的文件。此頁面用來分頁顯示 中將我們剛才建立的 樣做是因為項目采用至此,我們所需的文件已經(jīng)全部建立完成,login.aspx 用來登錄,登錄后到index.aspx 頁面,document文章表中的內(nèi)容,并且可以添加文章記錄。(注意,做好網(wǎng)頁后,需要在記事本login.aspx 、index.aspx 打開重新保存一下,保存編碼改為utf-8,覆蓋原文件即可,這utf-8編碼,如果不這樣的話,頁面含有中文的話就會顯示為亂碼。),如下圖:LTkifiK. iSpK(

7、存類型:編碼4):UTF-eI然后開始編碼,具體編碼和中的編碼過程一樣,不同的就是換成了mobile控件,這里需要注意的vs下開發(fā)wap不支持可視化設(shè)計,我們只能在后臺手工編碼,當(dāng)添加vmobile控件的時候,只要打上vm就會岀現(xiàn)你所需要的mobile控件,mobile控件的具體有哪些和都有什么屬性請參考其他文檔,日后若有時間,我會將 mobile控件的使用說明詳細(xì)介紹一下,這里給大家引薦一個網(wǎng)址,這里面有mobile控件的介紹和廿使用說明, 005 3.html我們這里只用到了objectlist 控件和textbox、textview 控件以及 comma nd Label控件,comma

8、 nc控件其實就是 butt on 按鈕,在 mobile 里叫 comma nd這里我們建立三個文件:logi n.aspx:登錄頁面in dex.as px:分頁顯示文章頁面,帶有快速發(fā)表view.as px:顯示文章具體內(nèi)容頁面三個頁面源代碼:logi n.aspx前臺代碼具體如下:.7.8.mobile:LabelID=z1 Runat=serverFont-Size=LargeForeColor=#3333cc 登錄窗口 9.!-lbl_out信息標(biāo)簽,初始隱藏,登錄失敗后或退出系統(tǒng)時顯示信息10.11.用戶名 :12.13.密碼: 14.!-密碼輸入框 :tb_Pwd

9、15.16.mobile:Command ID=Button1Runat=serverOnClick=Button1_OnClick登錄 !- 登錄按鈕0.login.aspx.cs21.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.usingSyste

10、m.Web.UI;10.usingSystem.Web.UI.MobileControls;11.usingSystem.Web.UI.WebControls;12.usingSystem.Web.UI.HtmlControls;13.usingSystem.Data.SqlClient;后臺代碼具體如下:14.15.16.namespace testWap17.18.publicpartial classloginSystem.Web.UI.MobileControls.MobilePtected voidPage_Load(objectsender, EventAr

11、gs e)21.22.#region if系統(tǒng)退出時將信息標(biāo)簽(SessionloginOutInfolbl_out 賦值并且顯示!= null)23.24.25.string outInfo this.lbl_out.TextSessionloginOutInfo.ToString();outInfo;26.this.lbl_out.Visibletrue;27.Session.Clear();28.29.#endregion30.31.32./33./34./35./36./登錄驗證37.38.protected void Button1_OnClick(objectsender, Eve

12、ntArgs e)53.56.40.string userpwd= this.tb_Pwd.Text.Trim();41.string strCon= Data Source=(local);Database=wapDB;Uid=sa;Pwd=zxkj;42.string strSql= select * from userinfo where user_name=+username+and user_pwd=+userpwd+;43.SqlConnectionconn = new SqlConnection(strCon);44.conn.Open();45.SqlDataAdapterda

13、 = new SqlDataAdapter(strSql, conn);46.DataSet ds =new DataSet();47.da.Fill(ds);48.conn.Close();49.50.int rowCount= ds.Tables0.Rows.Count;51.52.if (rowCount 0)39.stringthis.tb_User.Text.Trim();username54.Sessionusernameds.Tables0.Rows0user_name55.ToString().Trim();Response.Redirect(index.aspx);57.el

14、se58.59.this.lbl_out.Text用戶名密碼錯誤,請重新登錄H.60.this.lbl_out.Visibletrue;4. index.aspx前臺代碼具體如下:1.Inherits=testWap.indexCodebehind=i2.html xmlns=/1999/xhtmlmobile:Formmobile:Labelmobile:Labelid=Form1 runat=serverID=lbl_unameID=wtmobile:ObjectListmobile:LinkRunat=serverRunat=serve

15、rID=ObjectList1Runat=serverNavigateUrl= 文章列表Runat=server!-ObjectList控件Text=NAME=Title Wrapping=Wrap1ID=Title頁碼:lbl_page頁 | mobile:Linkmobile:Linkid=lnk_endrunat=serverid=lnk_prerunat=server頁 | mobile:Link1Visible=Falseid=lnk_next上一頁 BreakAfter=falserunat=serverRunat=server 發(fā)布文章 :下一頁 23. 首25.27. 28.

16、mobile:TextBoxID=tb_title29. mobile:TextBoxID=tb_content30. 發(fā)表Runat=serverRunat=serverID=Button4.ForeColor=Red 退出 index.aspx.cs后臺代碼具體如下:25.28.1.usingSystem;2.usingSystem.Collections;3.usingSystem.ComponentModel;4.usingSystem.Data;5.usingSystem.Drawing;6.usingSystem.Web;7.usingSystem.Web.M

17、obile;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;15.namespace testWap8.publicpartial classindexSystem.Web.UI.MobileControls.MobilePte

18、ctedvoidPage_Load(object sender, EventArgs e)21.if(Sessionusernamenull)22.23.SessionloginOutInfo登錄時間到,請重新登錄!24.Response.Redirect(login.aspx);26.this.lbluname.Text 歡迎您: +(string)Sessionusername;27.if(Sessionok!= null)29.this.lbl_error.Text 發(fā)表成功 !;30.this.lbl_error.Visibletrue;131.Sessionoknull;32.33.

19、if(!IsPostBack)34.35.Bind();9.40.privatevoidBind()42.int page = 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 = new PagedDataSource();56.string strCon= Data Source=(local);Database=wapDB;Uid=sa;Pwd=zxk

20、j;57.string strSql= select * from document orderby doc_desc;58.SqlConnection conn = new SqlConnection(strCon);59.conn.Open();60.SqlDataAdapterda = new SqlDataAdapter(strSql,conn);61.DataSet ds =new DataSet();62.da.Fill(ds);63.conn.Close();64.ps.DataSource =ds.Tables0.DefaultView;65.ps.AllowPaging= t

21、rue;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 -stringrPageRequest.Q

22、ueryStringPage;41.id74.);this.lnk_next.NavigateUrl =index.aspx?page= +(page +7 I75.this.lnk_end.NavigateUrl =index.aspx?page= +ps.PageCountI76.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_en

23、d.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();

24、96.97.98.protectedvoid Button2_OnClick(objectsender, EventArgse)99.100.string title = this.tb_title.Text.Trim();101.string content = this.tb_content.Text.Trim();102.if (title = | title= null | content= | content =null)103.104.this.lbl_error.Text= 文章標(biāo)題或內(nèi)容不能為空 !;105.this.lbl_error.Visible= true;106.re

25、turn;107.108.string strSql = insertdocument values( +title + , + content+ )1109.string strCon = Data Source=(local);Database=wapDB;Uid=sa;Pwd=zxkj;110.SqlConnection conn = newSqlConnection(strCon);111.conn.Open();112.SqlCommand com = new SqlCommand(strSql, conn);113.com.ExecuteNonQuery();114.conn.Cl

26、ose();115.Sessionokok;116.Response.Redirect(index.aspx);117.118.119.protectedvoidButton1_OnClick(objectsender, EventArgs e)120.121.try122.123.Session.Clear();124.SessionloginOutInfo 退出成功!H.125.126.catch127.128.SessionloginOutInfo 退出成功!H.129.130.Response.Redirect(login.aspx);131.132.133. view.aspx前臺代

27、碼具體如下:1.Namespace=System.Web.UI.MobileControlshtml xmlns=/1999/xhtmlmobile:Formmobile:Labelmobile:TextViewmobile:Labelmobile:TextViewmobile:LinkID=Label1Runat=serverForeColor=#0000cc帖子內(nèi)容ID=z1 Runat=serverForeColor=#0066ffID=tv_titleRunat=serverID=z2 Runat=serverID=tv_ContentID=lnk_Fa

28、nHuiAssembly=Sy標(biāo)題: Wrapping=Wrap內(nèi)容: ForeColor=#0066ffRunat=serverRunat=serverWrapping=Wrap返回上層BreakAfter=false 退出view.aspx.cs后臺代碼具體如下:39.40.1.usingSystem;2.usingSystem.Collections;3.usingSystem.ComponentModel;4.usingSystem.Data;5.usingSystem.Drawing;6.usingSystem.Web;7.usingSystem.Web.Mobile;8.using

29、System.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;15.16.namespace testWap17.18.publicpartial class viewSystem.Web.UI.MobileControls.MobilePtectedvoid Page_Load(object sender,EventArgs e)21.if(Sessionusernamenull| Sessionpagenul14.l)SessionloginOutInfo = 登錄時間到,請重新登錄! Response.Redirect(login.aspx);6.int docid =

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論