国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

asp+中文教程(三)-- 服務器端控制(一)

2024-05-04 11:06:26
字體:
來源:轉載
供稿:網友
 上次講了一些有關asp + 服務器端控制的內容,現在來詳細講一下。asp + 服務器端控制是微軟新提出的概念,它的實現是基于微軟的.net框架,它實際上是一種特殊的html元素,服務器端與它是交互的關系,在生成這些元素后不但能接受它們的值,還可以動態控制它們,以完成一些很cool的功能。下面列出所有asp + 目前支持的所有28個服務器端控制及其具體用法。

1、    adrotator : 廣告輪換服務器端控制,它的具體行為是在指定的xml文件里定義的,如下:

  <advertisements>
           <ad>
          <imageurl>/quickstart/aspplus/images/banner1.gif</imageurl>
          <navigateurl>http://www.microsoft.com</navigateurl>
          <alternatetext>microsoft.com</alternatetext>
          <keyword>computers</keyword>
          <impressions>80</impressions>
       </ad>
</advertisements>

屬性的含義:
<imageurl>:      要顯示得圖片絕對或相對路徑。
<navigateurl>:    點擊圖片所指向的url,如果為空則圖片不能被點擊。
<alternatetext>:  鼠標移動到圖片上所顯示的提示信息。
<keyword>:        指定改廣告頁面的過濾關鍵字。
<impressions>:    該廣告的顯示百分比,這個數值越高,顯示的次數越多。

2、    button: 這個好理解,類似于傳統表單中的button,但用法稍有不同,具體用法我就不祥述了。

3、    calendar: 一個很方便的日歷控制,這樣就不用再用javascript費勁編了,還得計算閏年什么的,要多煩有多煩,看下面的例子:

<html>
<head>

    <script language="c#" runat="server">

        void date_selected(object s, eventargs e) {
            label1.text = "selected date is: " + calendar1.selecteddate.toshortdatestring();
        }

    </script>

</head>

<body>

    <h3><font face="verdana">calendar example</font></h3>

    <form runat=server>

        <asp:calendar id=calendar1 onselectionchanged="date_selected" runat="server" />
        
        <p>
        
        <asp:label id=label1 runat="server" />
        
    </form>

</body>
</html>

這個控制帶有一個屬性selectionmode,它的具體屬性值如下:
day :            可以選擇任意一個單獨的日子。
dayweek:        可以選擇一天或一個星期。
dayweekmonth:   可以選擇一天或一個星期或一個月。
none:            不能選擇日期。


4、    checkbox :  檢查框嘛,沒什么好說的,但有一點不同,那就是如果它的autopostback屬性設為真,則點選它時可以提交到服務器端。

5、    checkboxlist : 顧名思義,一組可多選的檢查框列表,它有兩個重要的屬性,repeatlayout和repeatdirection,控制這個列表的布局,設成table則該列表以表格為底,如果設成flow,則沒有表格,repeatdirection默認為vertical,垂直排列,如果設為horizontally,則水平排列。

6、    comparevalidator :進行兩個服務器端控制的比較。它有三個不能缺少的重要屬性:controltovalidate , controltocompare 決定要比較那些控制,operator決定比較的方式,是等于、不等于、大于、小于等。具體實現看下面的例子:

  comparevalidator1.aspx

<%@ page clienttarget=downlevel %>

<html>
<head>
    <script language="c#" runat="server">

        void button1_onsubmit(object sender, eventargs e) {

            if (page.isvalid) {
               lbloutput.text = "result: valid!";
            }
            else {
               lbloutput.text = "result: not valid!";
            }
        }

        void lstoperator_selectedindexchanged(object sender, eventargs e) {

            comp1.operator = (validationcompareoperator) lstoperator.selectedindex;
            comp1.validate();
        }

   </script>

</head>
<body>

    <h3><font face="verdana">comparevalidator example</font></h3>
    <p>type a value in each textbox, select a comparison operator, then click "validate" to test.</p>

    <form runat=server>

      <table bgcolor="#eeeeee" cellpadding=10>
      <tr valign="top">
        <td>
            <h5><font face="verdana">string 1:</font></h5>
            <asp:textbox selected id="txtcomp" runat="server"></asp:textbox>
        </td>
        <td>
            <h5><font face="verdana">comparison operator:</font></h5>

            <asp:listbox id="lstoperator" onselectedindexchanged="lstoperator_selectedindexchanged" runat="server">
                    <asp:listitem selected value="equal" >equal</asp:listitem>
                    <asp:listitem value="notequal" >notequal</asp:listitem>
                    <asp:listitem value="greaterthan" >greaterthan</asp:listitem>
                    <asp:listitem value="greaterthanequal" >greaterthanequal</asp:listitem>
                    <asp:listitem value="lessthan" >lessthan</asp:listitem>
                    <asp:listitem value="lessthanequal" >lessthanequal</asp:listitem>
            </asp:listbox>
        </td>
        <td>
            <h5><font face="verdana">string 2:</font></h5>
            <asp:textbox id="txtcompto" runat="server"></asp:textbox><p>
            <asp:button runat=server text="validate" id="button1" onclick="button1_onsubmit" />
        </td>
      </tr>
      </table>

      <asp:comparevalidator id="comp1" controltovalidate="txtcomp" controltocompare = "txtcompto" type="string" runat="server"/>

      <br>
      
      <asp:label id="lbloutput" font-name="verdana" font-size="10pt" runat="server"/>

    </form>

</body>
</html>


7、    customvalidator:自定義比較,作用就是可以進行上述基本比較不能完成的比較操作。這個比較可以運行在服務器端,也可以運行在客戶端,如用vbscript或javascript。用法很簡單,看例子吧。

customvalidator1.aspx

<html>
<head>
    <script language="c#" runat=server>

        void validatebtn_onclick(object sender, eventargs e) {

            if (page.isvalid) {
               lbloutput.text = "page is valid!";
            }
            else {
               lbloutput.text = "page is not valid! :-(";
            }
        }

        bool servervalidate (object source, string value) {

            int num = int32.fromstring(value);
            
            if (num%2 == 0)
                return true;
            else
                return false;
        }
        
   </script>

</head>
<body>

<h3><font face="verdana">customvalidator example</font></h3>

<form runat="server">

    <asp:label id=lbloutput runat="server"
        text="enter an even number:"
        font-name="verdana"
        font-size="10pt" /><br>

    <p>

    <asp:textbox id=text1 runat="server" />
    
      

    <asp:customvalidator id="customvalidator1" runat="server"
        controltovalidate="text1"
        onservervalidationfunction="servervalidate"
        display="static"
        font-name="verdana" font-size="10pt">
           not an even number!
    </asp:customvalidator>

    <p>

    <asp:button text="validate" onclick="validatebtn_onclick" runat="server" />

</form>

</body>
</html>
菜鳥學堂:
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 凌海市| 兴仁县| 襄城县| 新蔡县| 关岭| 昭觉县| 定西市| 丰顺县| 盐源县| 中西区| 白山市| 天台县| 宜黄县| 凤台县| 樟树市| 沛县| 阜南县| 商洛市| 平谷区| 崇阳县| 调兵山市| 姜堰市| 兴山县| 泽库县| 桃源县| 东丽区| 建瓯市| 德庆县| 资中县| 开封县| 义马市| 高要市| 兴国县| 平武县| 堆龙德庆县| 清新县| 满城县| 卢湾区| 巴南区| 会宁县| 潮州市|