asp.net ajax 1.0 精选ajax controltookit控件介绍2

1  ajax 的tabcontrol
    在ajax 1.0中,有的tabcontrol是非常不错的了
    <cc1:TabContainer ID="TabContainer1" runat="server" OnClientActiveTabChanged="ActiveTabChanged"  Height="150px">
            <cc1:TabPanel ID="TabPanel1" runat="server" HeaderText="第1页">
                <ContentTemplate>
                     <asp:TextBox ID="TextBox1" runat="server" Text="第1页中的TextBox"></asp:TextBox>
                    <asp:Button ID="Button1" runat="server" Text="Button" />
                </ContentTemplate>
            </cc1:TabPanel>
             <cc1:TabPanel ID="TabPanel2" runat="server" HeaderText="第2页">
                <ContentTemplate>
                    <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
                </ContentTemplate>
            </cc1:TabPanel>
             <cc1:TabPanel ID="TabPanel3" runat="server" HeaderText="第3页">
                <ContentTemplate>
                    <asp:UpdatePanel runat="server">
                        <ContentTemplate>
                            <br>此页面被UpdatePanel所包覆<br>
                            <asp:TextBox ID="TextBox3" runat="server" Text="第3页中的TextBox" />
                            <asp:Button ID="Button3" runat="server" Text="Button" />
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </ContentTemplate>
            </cc1:TabPanel>
        </cc1:TabContainer>
 可以看到,一个tabcontrol里,有不同的tabpannel,就是“页”了,很简单,要注意,设置了OnClientActiveTabChanged的javscript事件,
是在切换页之间时做的
  <script type="text/javascript">
        function ActiveTabChanged(sender, e) {
            var CurrentTab = $get('<%=CurrentTab.ClientID%>');
            CurrentTab.innerHTML = sender.get_activeTab().get_headerText();
        }
    </script>
这段的意思是显示当前用户选择的是第几页


2 nobot控件
   电脑机器人,防止人为恶意攻击页面
CutoffWindowSeconds="60" 设置一个时段区间(单位:秒),与utoffMaximumInstances参数一起使用。

  • CutoffMaximumInstances="5" 与 CutoffWindowSeconds参数一起使用,例如在60秒内若超过5次读取此页面,将被判定为程序所为。
  • ResponseMinimumDelaySeconds="2" 页面合理的最低Postback时间(单位:秒),低于此时间Postback此页面将被判定为程序所为(不是人做的)
  • OnGenerateChallengeAndResponse="验证函数名称"
  • 后台判断逻辑代码
       If IsPostBack = True Then
                Dim NoBotState As AjaxControlToolkit.NoBotState
                '验证并取得状态
                If NoBot1.IsValid(NoBotState) = True Then
                    Label1.Text = ""
                Else
                    '检查状态
                    Select Case NoBotState
                        Case AjaxControlToolkit.NoBotState.InvalidAddressTooActive
                            Label1.Text = "在指定的时间内访问太多次,判定为程序所为"
                        Case AjaxControlToolkit.NoBotState.InvalidResponseTooSoon
                            Label1.Text = "在指定的时间内访问太多次,判定为程序所为" '"在太短的时间内响应此网页,判定为程序所为..."
                        Case Else
                            Label1.Text = "其它错误"
                    End Select
                End If
            End If

    3 password密码强度控件
        TargetControlID="要进行密码强度验证的Textbox控件ID"
    DisplayPosition="提示信息显示位置"
    StrengthIndicatorType="强度的体现方式(Text  / BarIndicator)"
    PreferredPasswordLength="建议密码长度"
    PrefixText="提示文字开头"
    HelpStatusLabelID="输入提示LLabel控件ID"
    MinimumNumericCharacters="设置密码中最少要有几个数值字符"
    MinimumSymbolCharacters="设置密码中最少要有几个符号字符"
    RequiresUpperAndLowerCaseCharacters="设置密码中是否一定需要大小写都包含"
    TextStrengthDescriptions="验证结果文字,最少两个最多10个"

    4  modalpopup控件
        这个控件的目的是可以弹出一个窗口,但弹出后,页面其他部分是变灰色的,不可用,当用户做出选择后,才可以用,十分好的效果
      用法:
    TargetControlID="设置哪一个控件要具有调用弹出式对话窗口的功能"
      PopupControlID="作为弹出式窗口的Panel控件ID"
        BackgroundCssClass="弹出式窗口背景画面CSS,可利用CSS设置为灰黑色半透明背景"
       
    DropShadow="是否绘制阴影(true/false)"
       
    OkControlID="弹出式对话窗口的Ok按钮ID"
        CancelControlID="弹出式对话窗口的Cancel按钮ID"
       
    OnOkScript="当点击Ok按钮后要执行的JavaScript"
        OnCancelScript="当点击Cancel按钮后要执行的JavaScript"
       
    PopupDragHandleControlID="作为弹出式窗口拖拽标签的控件ID"

     前端代码
     <asp:Label ID="Label1" runat="server" Text="按此Label触发对话窗口" BorderStyle="Ridge" BorderWidth="1px"></asp:Label><br />
            &nbsp;</div>
            <asp:Panel ID="Panel1" runat="server" Height="168px" Width="296px" BackColor="WhiteSmoke" style="display: none" BorderColor="#0000C0" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center">
                <span style="color: #ffffff">
                </span>
                <asp:Label ID="LBL_Title" runat="server" BackColor="Blue" Font-Bold="True" ForeColor="White"
                    Style="text-align: left" Text="标题" Width="100%"></asp:Label><br />
                <br />
                <asp:Label ID="Label2" runat="server" ForeColor="Black" Height="72px" Text="您确定要这么做?"
                    Width="100%"></asp:Label><br />
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
                <table style="width: 100%">
                    <tr>
                        <td align="right">
                <asp:Button ID="btn_OK" runat="server" Text="确定" />
                <asp:Button ID="btn_Cancel" runat="server" Text="取消" /></td>
                    </tr>
                </table>
                &nbsp;&nbsp;
            </asp:Panel>
            <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="Label1">
            </cc1:ModalPopupExtender>


    逻辑代码后台:
     

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            '设置哪一个控件要触发(显示)对话窗口
            Me.ModalPopupExtender1.TargetControlID = Me.Label1.ID
            '设置对话窗口
            Me.ModalPopupExtender1.PopupControlID = Me.Panel1.ID
            '当对话窗口出现时的背景样式
            Me.ModalPopupExtender1.BackgroundCssClass = "modalbackground"
            '是否要绘制阴影
            Me.ModalPopupExtender1.DropShadow = True
            Me.ModalPopupExtender1.OkControlID = btn_OK.ID
            '设置当点击OK钮时,要执行的前端JavaScript代码
            Me.ModalPopupExtender1.OnOkScript = "onOK()"
            Me.ModalPopupExtender1.CancelControlID = btn_Cancel.ID
            Me.ModalPopupExtender1.PopupDragHandleControlID = LBL_Title.ID
            '也可以通过Show方法来调用
            'Me.ModalPopupExtender1.Show()

            '在页面上注册一段JavaScript,点击OK钮时会调用到
            Dim js As String
            js = "<script>"
            js += "function onOK(){"
            js += "alert('你选择OK');"
            js += "}"
            js += "</script>"
            Me.ClientScript.RegisterStartupScript(GetType(String), "first", js)
        End Sub

    你可能感兴趣的:(asp.net)