`

3.2Page.IsValid

阅读更多
Page.IsValid

设置Display属性
Static
Dynamic
None

<span id="reqProductName" style="color:Red;Visibility:hidden;">(Required) </span>
<span id="reqProductName" style="color:Red;display:none;">(Required) </span>
  Visibility和display都能隐藏文本但是visibility属性隐藏文本仍然会占用屏幕空间,display不占屏幕空间。

通常情况下,应当将验证控件的Display属性设置为Dynamic,不会将内容推到右边。

突出显示验证错误
<asp:RequiredFieldValidator ID="reqProductQuantity" ControlToValidate="txtProductQuantity"
                Text="<img src='error.gif' alt='Fist name is required.'/>" Display="Dynamic" runat="server" />

SetFocusOnError="true"
<asp:RequiredFieldValidator ID="reqProductQuantity" ControlToValidate="txtProductQuantity"
                Text="<img src='error.gif' alt='Fist name is required.'/>"
setFocusOnError="true"
Display="Dynamic" runat="server" />


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
            lblLoginResult.Text = "Log in sucessful!";
       
    }

    protected void btnRegister_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
            lblRegisterResult.Text = "Registration sucessful!";
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head  id="Head1" runat="server">
<style type="text/css">
  html
  {
      background-color:Silver;
      }
    .column
    {
        float:left;
        width:300px;
        margin-left:10px;
        background-color:White;
        border:solid 1px black;
        padding:10px;
       
        }
</style>
    <title>Show Validation Groups</title>
</head>
<body>
    <form id="form1" runat="server">
    <div class="column">
     <fieldset>
       <legend>Login</legend>
       <p>
        Please log in to our Website.
       </p>
       <asp:Label ID="lblUserName"
       Text="User Name:"
       AssociatedControlID="txtUserName" runat="server"></asp:Label>
       <br />
       <asp:TextBox ID="txtUserName" runat="server" />
       <asp:RequiredFieldValidator ID="reqUserName"
       ControlToValidate="txtUserName" Text="(Required)" ValidationGroup="LoginGroup" runat="server" />
       <br /><br />
       <asp:Label ID="lblPassword" Text="Password:" AssociatedControlID="txtPassword" runat="server" />
       <br />
       <asp:TextBox ID="txtPassword" TextMode="Password" runat="server" />
       <asp:RequiredFieldValidator ID="reqPassword" ControlToValidate="txtPassword" Text="(Required)"
        ValidationGroup="LoginGroup" Runat="server"/>
        <br /><br />
        <asp:Button ID="btnLogin" Text="Login" ValidationGroup="LoginGroup" runat="server" OnClick="btnLogin_Click" />

     </fieldset>
     <asp:Label ID="lblLoginResult" runat="server" />
    </div>
    <div class="column">
    <fieldset>
     <legend>Register</legend>
     <p>If you do not have a User Name,please register at our WebSite.</p>
     <asp:Label ID="lblFirstName" Text="First Name:"
      AssociatedControlID="txtFirstName" runat="server" />
      <br />
      <asp:TextBox ID="txtFirstName" runat="server" />
      <asp:RequiredFieldValidator ID="reqFirstName" ControlToValidate="txtFirstName"
       Text="(Required)" ValidationGroup="RigsterGroup" runat="server" />
       <br /><br />
        <asp:Label ID="lblLastName" Text="Last Name:"
      AssociatedControlID="txtLastName" runat="server" />
      <br />
      <asp:TextBox ID="txtLastName" runat="server" />
      <asp:RequiredFieldValidator ID="reqLastName" ControlToValidate="txtLastName"
       Text="(Required)" ValidationGroup="RigsterGroup" runat="server" />
       <br /><br />
       <asp:Button ID="btnRegister" Text="Register" ValidationGroup="RigsterGroup" runat="server" OnClick="btnRegister_Click" />
    </fieldset>
    <asp:Label ID="lblRegisterResult" runat="server" />
    </div>
    </form>
</body>
</html>

2011-4-26 11:32 danny


分享到:
评论

相关推荐

    ZendFramework中文文档

    Querying if the input is valid 14.5.3.2. Getting Invalid, Missing, or Unknown Fields 14.5.3.3. Getting Valid Fields 14.5.4. Using Metacommands to Control Filter or Validator Rules 14.5.4.1. The ...

    ti dsp tms2802芯片资料

    2.2.4 Data Page Pointer (DP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10 2.2.5 Stack Pointer (SP) . . . . . . . . . . . . . . . . . . . . . . . . . ....

    Python Cookbook, 2nd Edition

    Recipe 3.2. Finding Last Friday Recipe 3.3. Calculating Time Periods in a Date Range Recipe 3.4. Summing Durations of Songs Recipe 3.5. Calculating the Number of Weekdays Between Two Dates ...

    django form

    if form.is_valid(): form.save() return redirect('success_url') # Redirect to a success URL else: form = PublisherForm() return render(request, 'books/publisher_add.html', {'form': form}) ``` #...

    DP83848CVV.pdf

    3.2 Reduced mll Interface 3.3 10 Mb Serial Network Interface(SNI) .22 3. 4 802.3u Mll Serial Management Interface 3.4.1 Serial Management Register Access 3.4.2 Serial Management Access protocol 22 ...

    ASP.NET 控件的使用

    3.1.2 使用Page.IsValid 85 3.1.3 设置Display属性 86 3.1.4 突出显示验证错误 86 3.1.5 使用验证组 90 3.1.6 禁用验证 93 3.2 使用RequiredFieldValidator控件 94 3.3 使用RangeValidator控件 97 3.4 使用...

Global site tag (gtag.js) - Google Analytics