Using both server side validation and client side validation

Discussion in 'ASP .Net' started by =?Utf-8?B?dmlkeWE=?=, Jun 2, 2005.

  1. Hi,

    I have a button which is a web control. I have some validation in javascript
    for the button in .aspx file and some in the button onclick event in code
    behind(C#). I need to get through both the java script validation as well as
    the click in code behind? How can this be done ? Can I call the code behind
    from the javascript function?
    If not can i have a separate procedure in C# file and call it from the
    javascript function? If so what is the syntax for it?
    Please let me know even if it's silly as I am pretty new to .net
     
    =?Utf-8?B?dmlkeWE=?=, Jun 2, 2005
    #1
    1. Advertising

  2. Hi vidya,

    In HTML, there is a "last chance" event that fires when a form is submitted,
    called "onsubmit". If you create a JavaScript "onsubmit" event handler for
    the form, a function that returns true or false, you can have a client-side
    validation script that fires before the server-side validation. Here's an
    example:

    <form name="MyForm" action="ThisUrl" onsubmit="return myValidation(this)">

    Any time you wire up a server-side event handler for a Web Control, what
    happens is this: A client-side JavaScript event handler for the client-side
    HTML form element of that Web Control is added to its HTML. That client-side
    event handler puts data about what element fired the event and any
    additional event-related data, into a couple of hidden HTML form fields that
    are also added to the HTML form. The client-side event handler then submits
    the form via JavaScript. This fires the "onsubmit" event of the client-side
    HTML form. When you add a JavaScript "onsubmit" event handler to the form,
    you are intercepting that form post event, and if your JavaScript function
    returns true, the form is submitted. If it returns false, the form submit is
    aborted.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Ambiguity has a certain quality to it.

    "vidya" <> wrote in message
    news:...
    > Hi,
    >
    > I have a button which is a web control. I have some validation in
    > javascript
    > for the button in .aspx file and some in the button onclick event in code
    > behind(C#). I need to get through both the java script validation as well
    > as
    > the click in code behind? How can this be done ? Can I call the code
    > behind
    > from the javascript function?
    > If not can i have a separate procedure in C# file and call it from the
    > javascript function? If so what is the syntax for it?
    > Please let me know even if it's silly as I am pretty new to .net
    >
     
    Kevin Spencer, Jun 2, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karim
    Replies:
    3
    Views:
    451
    Karim
    Nov 26, 2003
  2. Matt
    Replies:
    14
    Views:
    4,109
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  3. Lau Alvin
    Replies:
    4
    Views:
    552
  4. Giri
    Replies:
    1
    Views:
    403
    Peter Blum
    Dec 24, 2004
  5. Boss302
    Replies:
    0
    Views:
    1,056
    Boss302
    Nov 21, 2006
Loading...

Share This Page