首页 > 开发 > .Net > 正文

让您的主页支持各种浏览设备(ASP.NET篇)(上)

2019-10-27 13:48:24
字体:
来源:转载
供稿:网友

  前面我们看到了对于移动控件的介绍,现在我们具体来看看他的用法.

使用移动控制
使用移动控制就和使用其它asp+控制一样简单。事实上他更加简单,因为他是产生整个页面,而不是部分页面。我们甚至
不必去考虑<? xml ....?>和<doctype .......>这些标签,他们会自动添加。

我们使用paner控制来产生<card>和<deck>

<mobile:panel runat="server" id="pnlmain">
  <mobile:form runat="server">
    <mobile:label runat="server">enter your name:</mobile:label>
    <mobile:textbox runat="server" id="nameedit" />
    <mobile:command runat="server" id="button" label="ok"
            targettype="formaccept" onclick="button_onclick" />
  </mobile:form>
</mobile:panel> 

注意:在以前的版本中,每个页面必须有一个mobile:form,现在不需要了。

下面是上面的程序在普通浏览器上看到的结果:



但是,如果您用wap手机来观看,就会看到下面的结果 :



下面我们将在页面中加上一个包含用户名的欢迎信息,因此我们得在这个deck中加上另外一个panel控制。

<mobile:panel runat=server id="pnltwo">
  <mobile:form runat="server">
    <mobile:label runat="server" id="welcomemessage" type="title"/>
  </mobile:form>
</mobile:panel>

我们让用户按下ok键后再显示这个信息。在wap手机中有不同的操作方法,意思一样。所以,我们还得写一此vb代码来处理
这个事件。

<script language="vb" runat="server">
  sub button_onclick(sender as object, args as eventargs)
    welcomemessage.text = "welcome '" & nameedit.text & "'"
    setcurrentpanel (pnltwo)
  end sub
</script>

在第一个card(或者是panel)中包含一个command控制,它指定了事件和铵钮的名字:

<mobile:command runat="server" id="button" label="ok"
  targettype="formaccept" onclick="button_onclick" />

子程序中的代码主要是用于从textbox控制中收集用户名,然后在第二个panel中的labael显示:

welcomemessage.text = "welcome '" & nameedit.text & "'"

当这些都完成了,我们就来启动每个页面

setcurrentpanel (pnltwo)

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表