Results 1 to 3 of 3

Thread: Vaildation... sometimes

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183

    Vaildation... sometimes

    I have a textbox for a username, a bunch of other ones for other info, and two buttons at the bottom of the page: One to login and another that hides the current panel and shows another panel with information about creating a new account.

    Now I want to have a required validation on the username box, so I add a required field validator, but the problem is that if the person wants to see the information panel instead of logining in they can't, they have to provide a username....

    how do I avoid this?

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    Set the CausesValidation attribute on the button that hides/shows the panel to False.
    VB Code:
    1. <script language="vb" runat="server">
    2. Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    3.  
    4. End Sub
    5. Sub Login_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    6.     Response.Write("Logged in!")
    7. End Sub
    8. Sub ShowSomething_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    9.     If Something.Visible Then
    10.         Something.Visible = False
    11.     Else
    12.         Something.Visible = True
    13.     End If
    14. End Sub
    15. </script>
    16. <html>
    17.     <body>
    18.         <form id="ConditionalValidation" runat="server">
    19.             UserName:
    20.             <asp:TextBox
    21.                 ID="UserName"
    22.                 Runat="server"/>
    23.             <asp:RequiredFieldValidator
    24.                 ID="UserNameRequired"
    25.                 Runat="server"
    26.                 ControlToValidate="UserName"
    27.                 ErrorMessage="*"
    28.                 ToolTip="UserName is required!"
    29.                 Display="Dynamic"/>
    30.             <br />
    31.             <asp:Button
    32.                 ID="Login"
    33.                 Runat="server"
    34.                 OnClick="Login_Click"
    35.                 Text="Login!"/>
    36.             <asp:Button
    37.                 ID="ShowSomething"
    38.                 Runat="server"
    39.                 CausesValidation="False"
    40.                 OnClick="ShowSomething_Click"
    41.                 Text="Show Something"/>
    42.             <br />
    43.             <asp:Label
    44.                 Visible="False"
    45.                 ID="Something"
    46.                 Text="Here's Something!"
    47.                 Runat="server"/>
    48.         </form>
    49.     </body>
    50. </html>

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183

    Resolved

    Awesome thanks for that I figured it had to be something simple.. just couldn't find it anywhere

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width