.NET question about code behind

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marylipscomb
    New Member
    • Apr 2007
    • 51

    .NET question about code behind

    Say for example on the ASP.NET form I put a Username and password,
    I validate it on that form with the validation buttons.

    Now I go to the .vb code and put in what I want as far as the username and password and what happens when you click the submit button,


    Protected Sub btnSubmit_Click (ByVal sender As Object, ByVal e As System.EventArg s) Handles btnSubmit.Click
    If ((txtPassword.T ext = "pass") & (txtUsername.Te xt = "mary")) Then
    Response.Cookie s("Username").V alue = txtUsername.Tex t
    Response.Redire ct("bid1main.as px")
    Else
    lblMessage.Text = "<font color = red> Sorry, " & "invalid username and/or password!</font>"


    the code there about the lblMessage.Text , What happens to the validation code that is in the asp page??? I hope this makes since to someone.
    How do I validate it here on the .vb page when it is already validated??

    Thank you for anyone who understands and can help me!!!
  • marylipscomb
    New Member
    • Apr 2007
    • 51

    #2
    For example.. here is my aspx code: the whole code behind thing would kinda rewrite this wouldn't it??

    <asp:Label ID="lblUsername " runat="server" Font-Bold="True" Text="Username: " Width="128px"></asp:Label>
    <asp:TextBox ID="txtUsername " runat="server"> </asp:TextBox>
    <asp:RequiredFi eldValidator ID="rfvUsername " runat="server" ControlToValida te="txtUsername "
    Display="Dynami c" ErrorMessage="P lease enter a valid Username">*</asp:RequiredFie ldValidator>
    <asp:RegularExp ressionValidato r ID="revUsername " runat="server" ControlToValida te="txtUsername "
    ErrorMessage="P lease enter a valid username"></asp:RegularExpr essionValidator ><br />
    <br />
    <asp:Label ID="lblPassword " runat="server" Font-Bold="True" Text="Password: " Width="128px"></asp:Label>
    <asp:TextBox ID="txtPassword " runat="server"> </asp:TextBox>
    <asp:RequiredFi eldValidator ID="rfvPassword " runat="server" ControlToValida te="txtPassword "
    ErrorMessage="P lease enter a valid Password">*</asp:RequiredFie ldValidator>
    <asp:RegularExp ressionValidato r ID="revPassword " runat="server" ControlToValida te="txtPassword "
    Display="Dynami c" ErrorMessage="Y our password must be at least 4 characters long"
    ValidationExpre ssion="\w{4,}"> </asp:RegularExpr essionValidator ><br />
    <br />
    <asp:Button ID="btnSubmit" runat="server" Height="32px" Text="Submit" Width="80px" /><br />
    <br />

    thanks

    Comment

    • marylipscomb
      New Member
      • Apr 2007
      • 51

      #3
      I FIGURED IT OUT!!!!!!!!!!!! !!!!!!!!!! WOOOOOOOHOOOOOO O


      *pats self on back*

      Comment

      • kunal pawar
        Contributor
        • Oct 2007
        • 297

        #4
        There is some mistakes in your code First Modify it and then check it works

        Protected Sub btnSubmit_Click (ByVal sender As Object, ByVal e As System.EventArg s) Handles btnSubmit.Click
        If Trim(txtPasswor d.Text) = "pass" and Trim(txtUsernam e.Text) = "mary" Then
        Response.Cookie s("Username").V alue = Trim(txtUsernam e.Text)
        Response.Redire ct("bid1main.as px")
        Else
        lblMessage.Text = "<font color = red> Sorry, " & "invalid username and/or password!</font>"
        end if

        Comment

        Working...