用asp.net開發wap網站

來源:互聯網
上載者:User

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Mobile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class viewBook : System.Web.UI.MobileControls.MobilePage
{
    public int dxClass;
    public int curpage;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["menuID"] != null)
        {
            dxClass = Int32.Parse(Request.QueryString["menuID"].ToString());
        }

        if (!this.IsPostBack)
        {
            this.Bind();
        }

    }

    //擷取目錄
    private DataSet getMenuDs(int menuID)
    {
        OleDbConnection con = new OleDbConnection(@"provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath("App_Data/dx.mdb"));
        con.Open();
        string strCmd = "select * from menu where from=" + menuID;
        OleDbDataAdapter da = new OleDbDataAdapter(strCmd, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        return ds;
    }

    //資料繫結
    private void Bind()
    {
        this.List1.Items.Clear();

        DataSet menuDs = getMenuDs(dxClass);

        this.Label3.Text = Convert.ToString(menuDs.Tables[0].Rows.Count / 10 + 1);

        curpage = Int32.Parse(this.Label2.Text);//當前頁

        //如果當前頁是第一頁,並且只有一頁面,那麼不顯示按鈕
        if (this.Label2.Text == this.Label3.Text&&this.Label2.Text=="1")
        {
            this.Command1.Visible = false;
            this.Command2.Visible = false;
        }
        else if (this.Label2.Text =="1")//如果當前頁是第一頁,上一頁按鈕不顯示
        {
            this.Command1.Visible = false;
            this.Command2.Visible = true;
        }
        else if (this.Label2.Text == this.Label3.Text)//當前頁是最後一頁,那麼下一頁按鈕不顯示
        {
            this.Command1.Visible = true;
            this.Command2.Visible = false;
        }
        else
        {
            this.Command1.Visible = true;
            this.Command2.Visible = true;
        }

        if (Convert.ToInt32(this.Label2.Text)  == Convert.ToInt32(this.Label3.Text))
        {
            for (int i = (curpage - 1) * 10; i < menuDs.Tables[0].Rows.Count; i++)
            {
                string dxShort = menuDs.Tables[0].Rows[i]["menuName"].ToString();
                MobileListItem item = new MobileListItem(dxShort, "viewList.aspx?bookID=" + menuDs.Tables[0].Rows[i]["menuID"].ToString());
                this.List1.Items.Add(item);
            }
        }
        else
        {
            for (int i = (curpage - 1) * 10; i < curpage * 10 - 1; i++)
            {
                string dxShort = menuDs.Tables[0].Rows[i]["menuName"].ToString();
                MobileListItem item = new MobileListItem(dxShort, "viewList.aspx?bookID=" + menuDs.Tables[0].Rows[i]["menuID"].ToString());
                this.List1.Items.Add(item);
            }
        }

    }
    //上一頁
    protected void Command1_Click(object sender, EventArgs e)
    {
        this.Label2.Text = Convert.ToString(Int32.Parse(this.Label2.Text) - 1);
        this.Bind();
    }
    //下一頁
    protected void Command2_Click(object sender, EventArgs e)
    {
        this.Label2.Text = Convert.ToString(Int32.Parse(this.Label2.Text) + 1);
        this.Bind();
    }
}

1,格式

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.1//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>document title</title>
</head>
<body>
</body>
</html>

 

撥打到電話
<a href="wtai://wp/mc;13888888888">Call Me Now</a>

 

訪問asp網站的時候會根據訪問的裝置,輸出不同的內容,如果用IE訪問就輸出的是html,手機訪問,輸出就是WML。是什麼讓他這麼智能化呢?關鍵之處就在設定檔的<browserCaps>節!

在webconfig中加上這個,他可以強制輸出wml,還有其他的移動設定屬性都在這。

<browserCaps>
            <result type="System.Web.Mobile.MobileCapabilities, System.Web.Mobile, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <use var="HTTP_USER_AGENT"/>

            browser=Unknown
            version=0.0
            majorversion=0
            minorversion=0
            frames=false
            tables=false
            cookies=false
            backgroundsounds=false
            vbscript=false
            javascript=false
            javaapplets=false
            activexcontrols=false
            win16=false
            win32=false
            beta=false
            ak=false
            sk=false
            aol=false
            crawler=false
            cdf=false
            gold=false
            authenticodeupdate=false
            tagwriter=System.Web.UI.Html32TextWriter
            ecmascriptversion=0.0
            msdomversion=0.0
            w3cdomversion=0.0
            platform=Unknown
            css1=false
            css2=false
            xml=false

            mobileDeviceManufacturer = "Unknown"
            mobileDeviceModel = "Unknown"

            gatewayVersion = "None"
            gatewayMajorVersion = "0"
            gatewayMinorVersion = "0"

           preferredRenderingType = "wml11"
           preferredRenderingMime = "text/vnd.wap.wml"
           preferredImageMime = "image/vnd.wap.wbmp"

            defaultScreenCharactersWidth = "12"
            defaultScreenCharactersHeight = "6"
            defaultScreenPixelsWidth = "96"
            defaultScreenPixelsHeight = "72"
            defaultCharacterWidth = "8"
            defaultCharacterHeight = "12"
            screenBitDepth = "1"
            isColor = "false"
            inputType = "telephoneKeypad"

            numberOfSoftkeys = "0"
            maximumSoftkeyLabelLength = "5"

            canInitiateVoiceCall = "false"

            canSendMail = "true"
            hasBackButton = "true"
            rendersWmlDoAcceptsInline = "true"
            rendersWmlSelectsAsMenuCards = "true"
            rendersBreaksAfterWmlAnchor = "false"
            rendersBreaksAfterWmlInput = "false"
            rendersBreakBeforeWmlSelectAndInput = "true"
            requiresAttributeColonSubstitution = "true"
            requiresPhoneNumbersAsPlainText = "false"
            requiresUrlEncodedPostfieldValues = "false"
            requiredMetaTagNameValue = ""
            rendersBreaksAfterHtmlLists = "true"
            requiresUniqueHtmlCheckboxNames = "true"
            requiresUniqueHtmlInputNames = "true"
            requiresUniqueFilePathSuffix = "true"
            supportsCss = "false"
            hidesRightAlignedMultiselectScrollbars = "false"
            canRenderAfterInputOrSelectElement = "true"
            canRenderInputAndSelectElementsTogether = "true"
            canRenderOneventAndPrevElementsTogether = "true"
            canCombineFormsInDeck = "true"
            canRenderMixedSelects = "true"
            canRenderPostBackCards = "true"
            canRenderSetvarZeroWithMultiSelectionList = "true"
            supportsImageSubmit = "true"
            supportsSelectMultiple = "true"
            requiresHtmlAdaptiveErrorReporting = "false"
            requiresContentTypeMetaTag = "false"
            requiresDBCSCharacter = "false"
            requiresOutputOptimization = "false"
            supportsAccesskeyAttribute = "false"
            supportsInputIStyle = "false"
            supportsInputMode = "false"
            supportsIModeSymbols = "false"
            supportsJPhoneSymbols = "false"
            supportsJPhoneMultiMediaAttributes = "false"
            maximumRenderedPageSize = "2000"
            requiresSpecialViewStateEncoding = "false"
            requiresNoBreakInFormatting = "false"
            requiresLeadingPageBreak = "false"
            supportsQueryStringInFormAction = "true"
            supportsCacheControlMetaTag = "true"
            supportsUncheck = "true"
            canRenderEmptySelects = "true"
            supportsRedirectWithCookie = "true"
            supportsEmptyStringInCookieValue = "true"
            cachesAllResponsesWithExpires = "false"
            requiresNoSoftkeyLabels = "false"
            defaultSubmitButtonLimit = "1"
            
            supportsBold = "false"
            supportsItalic = "false"
            supportsFontSize = "false"
            supportsFontName = "false"
            supportsFontColor = "true"
            supportsBodyColor = "true"
            supportsDivAlign = "true"
            supportsDivNoWrap = "false"
            supportsCharacterEntityEncoding = "true"

            isMobileDevice="false"
</browserCaps> 
另外通過設定
         Page.Response.Expires = -1;
   Response.CacheControl = "Public";
可以取消行動裝置緩衝,並通過RedirectToMobilePage函數進行重新導向。

 最後手機中的。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.