Results 1 to 2 of 2

Thread: Client/Server operation from 1 button

  1. #1

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Client/Server operation from 1 button

    In an asp.net page/webform, lets say I have 2 textboxes (for the user to enter a username & password), and 1 cmdOk command button.
    What I want to do is check the 2 textboxes & see if they have values in & aren't blank, with a client-side javascript function - something like:
    Code:
        onclick="ValidateTxtBoxes()"
    With the same button, I also want to go back to the server & check this login (the username & password entered) against a database. Is there some way I could do both checks from 1 button? i.e. something like:
    Code:
        // Javascript Code called from the onclick event of the button as above
        function ValidateTxtBoxes()
        {
            if ( //User has left one of the boxes blank)
            {
                //show them an error message label or alert box
                //the page never goes back to the server & client side evaluation is performed
            }
            else
            {
                Call MyWebForm.VBCodePart.Function1()
                //call some vb code in the codebehind window of the asp.net webform
                //the page is sent back to the server & data is evaluated against a database
            }
        }
    Is this possible please? I don't want the overhead of a round trip to the server if the users just left one of the boxes blank...
    Thanks everyone!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    Why not just make those two fields required?(ie. use a RequiredFieldValidator)

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