access validation info in client script

Discussion in 'ASP .Net Web Controls' started by Velvet, Feb 22, 2007.

  1. Velvet

    Velvet Guest

    Does anyone know a way to force the client script to preform a client-side
    validation for controls in validation groups?

    What is currently happening is I have two validation groups (Billing,
    CreditCard). The validation doesn't happen until the submit button is
    pressed and the server validation happens. I added an OnClickClient event
    to the submit button that pops up a comfirm box, but it pops before any
    validation happens.

    What I would like to do is validate the form with client script and if it's
    valid, then pop up the credit card charge confirmation box. Once that's
    confirmed then run the server-side validation.

    Any one have any ideas or know of an article out there?

    Thanks!
    Velvet, Feb 22, 2007
    #1
    1. Advertising

  2. Velvet

    Zeba Guest

    On Feb 23, 4:48 am, "Velvet" <> wrote:
    > Does anyone know a way to force the client script to preform a client-side
    > validation for controls in validation groups?
    >
    > What is currently happening is I have two validation groups (Billing,
    > CreditCard). The validation doesn't happen until the submit button is
    > pressed and the server validation happens. I added an OnClickClient event
    > to the submit button that pops up a comfirm box, but it pops before any
    > validation happens.
    >
    > What I would like to do is validate the form with client script and if it's
    > valid, then pop up the credit card charge confirmation box. Once that's
    > confirmed then run the server-side validation.
    >
    > Any one have any ideas or know of an article out there?
    >
    > Thanks!


    I'm not sure I got you right, and Im rather hesitant to respond as I'm
    new to .net & JS myself, but can't you just give a call to a
    javascript validate function in the onSubmit . If the validation
    succeeds you can give a confirmation box (at the end of the function).
    If validation fails or user clicks cancel return false. Else return
    true.

    Zeba
    Zeba, Feb 23, 2007
    #2
    1. Advertising

  3. Hi Velvet,

    You could create a javascript function and assign it to the form's onsubmit
    handler. In this way, this javascript function will be called before
    submitting the form, if you return false, the form will not be submitted;
    and if the page didn't pass client-side validation, the onsubmit will not
    be fired.

    #Followers of the IHttpHandler : No more hijacking of __doPostBack in
    Whidbey
    http://weblogs.asp.net/vga/archive/2004/03/01/NoMoreHijackingOfDoPostBackInW
    hidbey.aspx

    #onsubmit Event (FORM)
    http://msdn2.microsoft.com/en-us/library/ms536972.aspx


    Sincerely,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications. If you are using Outlook Express, please make sure you clear the
    check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
    promptly.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Feb 23, 2007
    #3
  4. Velvet

    Velvet Guest

    Adding my confirm box to the form instead of the button worked great and was
    the simple solution! Thanks!

    Form.Attributes.Add("onclick", "if(!confirm('Your credit card will be billed
    for " + totalPrice.ToString("C") +

    " for this order.')){return false;}");

    Velvet



    "Walter Wang [MSFT]" <> wrote in message
    news:...
    > Hi Velvet,
    >
    > You could create a javascript function and assign it to the form's
    > onsubmit
    > handler. In this way, this javascript function will be called before
    > submitting the form, if you return false, the form will not be submitted;
    > and if the page didn't pass client-side validation, the onsubmit will not
    > be fired.
    >
    > #Followers of the IHttpHandler : No more hijacking of __doPostBack in
    > Whidbey
    > http://weblogs.asp.net/vga/archive/2004/03/01/NoMoreHijackingOfDoPostBackInW
    > hidbey.aspx
    >
    > #onsubmit Event (FORM)
    > http://msdn2.microsoft.com/en-us/library/ms536972.aspx
    >
    >
    > Sincerely,
    > Walter Wang (, remove 'online.')
    > Microsoft Online Community Support
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications. If you are using Outlook Express, please make sure you clear the
    > check box "Tools/Options/Read: Get 300 headers at a time" to see your
    > reply
    > promptly.
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
    Velvet, Feb 23, 2007
    #4
  5. Velvet

    Velvet Guest

    I spoke too soon... Still not quite right, but now I have a direction.

    Thanks!

    "Velvet" <> wrote in message
    news:%...
    > Adding my confirm box to the form instead of the button worked great and
    > was the simple solution! Thanks!
    >
    > Form.Attributes.Add("onclick", "if(!confirm('Your credit card will be
    > billed for " + totalPrice.ToString("C") +
    >
    > " for this order.')){return false;}");
    >
    > Velvet
    >
    >
    >
    > "Walter Wang [MSFT]" <> wrote in message
    > news:...
    >> Hi Velvet,
    >>
    >> You could create a javascript function and assign it to the form's
    >> onsubmit
    >> handler. In this way, this javascript function will be called before
    >> submitting the form, if you return false, the form will not be submitted;
    >> and if the page didn't pass client-side validation, the onsubmit will not
    >> be fired.
    >>
    >> #Followers of the IHttpHandler : No more hijacking of __doPostBack in
    >> Whidbey
    >> http://weblogs.asp.net/vga/archive/2004/03/01/NoMoreHijackingOfDoPostBackInW
    >> hidbey.aspx
    >>
    >> #onsubmit Event (FORM)
    >> http://msdn2.microsoft.com/en-us/library/ms536972.aspx
    >>
    >>
    >> Sincerely,
    >> Walter Wang (, remove 'online.')
    >> Microsoft Online Community Support
    >>
    >> ==================================================
    >> Get notification to my posts through email? Please refer to
    >> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    >> ications. If you are using Outlook Express, please make sure you clear
    >> the
    >> check box "Tools/Options/Read: Get 300 headers at a time" to see your
    >> reply
    >> promptly.
    >>
    >> Note: The MSDN Managed Newsgroup support offering is for non-urgent
    >> issues
    >> where an initial response from the community or a Microsoft Support
    >> Engineer within 1 business day is acceptable. Please note that each
    >> follow
    >> up response may take approximately 2 business days as the support
    >> professional working with you may need further investigation to reach the
    >> most efficient resolution. The offering is not appropriate for situations
    >> that require urgent, real-time or phone-based interactions or complex
    >> project analysis and dump analysis issues. Issues of this nature are best
    >> handled working with a dedicated Microsoft Support Engineer by contacting
    >> Microsoft Customer Support Services (CSS) at
    >> http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >> ==================================================
    >>
    >> This posting is provided "AS IS" with no warranties, and confers no
    >> rights.
    >>

    >
    >
    Velvet, Feb 23, 2007
    #5
  6. Velvet

    Velvet Guest

    This seems to work a bit better:

    ButtonFinish.OnClientClick = "if(Page_ClientValidate()){if(!confirm('Your
    credit card will be billed for " + totalPrice.ToString("C") + " for this
    order.')){return false;}}";
    This is on the button I wanted to use for submit. I have two other buttons
    on the page and the onclick for the form would pop my confirm message for
    the other two buttons as well. I tried setting the UseSubmitBehavior to
    false, hoping that would keep the buttons from causing the submit, but it
    didn't.

    So Instead I found the js file that is specified in this article:

    http://aspalliance.com/699#Page4

    I then found the validation call for the client side script and used it in
    the OnClientOnclick before the confirmation button. This works like a
    charm!

    Note: I did NOT make any changes to the JS file as the article suggests.

    Thanks again!

    "Velvet" <> wrote in message
    news:...
    >I spoke too soon... Still not quite right, but now I have a direction.
    >
    > Thanks!
    >
    > "Velvet" <> wrote in message
    > news:%...
    >> Adding my confirm box to the form instead of the button worked great and
    >> was the simple solution! Thanks!
    >>
    >> Form.Attributes.Add("onclick", "if(!confirm('Your credit card will be
    >> billed for " + totalPrice.ToString("C") +
    >>
    >> " for this order.')){return false;}");
    >>
    >> Velvet
    >>
    >>
    >>
    >> "Walter Wang [MSFT]" <> wrote in message
    >> news:...
    >>> Hi Velvet,
    >>>
    >>> You could create a javascript function and assign it to the form's
    >>> onsubmit
    >>> handler. In this way, this javascript function will be called before
    >>> submitting the form, if you return false, the form will not be
    >>> submitted;
    >>> and if the page didn't pass client-side validation, the onsubmit will
    >>> not
    >>> be fired.
    >>>
    >>> #Followers of the IHttpHandler : No more hijacking of __doPostBack in
    >>> Whidbey
    >>> http://weblogs.asp.net/vga/archive/2004/03/01/NoMoreHijackingOfDoPostBackInW
    >>> hidbey.aspx
    >>>
    >>> #onsubmit Event (FORM)
    >>> http://msdn2.microsoft.com/en-us/library/ms536972.aspx
    >>>
    >>>
    >>> Sincerely,
    >>> Walter Wang (, remove 'online.')
    >>> Microsoft Online Community Support
    >>>
    >>> ==================================================
    >>> Get notification to my posts through email? Please refer to
    >>> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    >>> ications. If you are using Outlook Express, please make sure you clear
    >>> the
    >>> check box "Tools/Options/Read: Get 300 headers at a time" to see your
    >>> reply
    >>> promptly.
    >>>
    >>> Note: The MSDN Managed Newsgroup support offering is for non-urgent
    >>> issues
    >>> where an initial response from the community or a Microsoft Support
    >>> Engineer within 1 business day is acceptable. Please note that each
    >>> follow
    >>> up response may take approximately 2 business days as the support
    >>> professional working with you may need further investigation to reach
    >>> the
    >>> most efficient resolution. The offering is not appropriate for
    >>> situations
    >>> that require urgent, real-time or phone-based interactions or complex
    >>> project analysis and dump analysis issues. Issues of this nature are
    >>> best
    >>> handled working with a dedicated Microsoft Support Engineer by
    >>> contacting
    >>> Microsoft Customer Support Services (CSS) at
    >>> http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >>> ==================================================
    >>>
    >>> This posting is provided "AS IS" with no warranties, and confers no
    >>> rights.
    >>>

    >>
    >>

    >
    >
    Velvet, Feb 23, 2007
    #6
  7. Hi Velvet,

    Instead of calling Page_ClientValidate() directly in your script, you
    should be able to achieve the same objective by simply doing:

    <script language="javascript" type="text/javascript">

    function mySubmit()
    {
    if (!confirm('Your credit card will be billed for " +
    totalPrice.ToString("C") + " for this order.")) {
    return false;
    }
    return true;
    }

    </script>

    <form onsubmit="return mySubmit();" ...>


    But of course this only works in ASP.NET 2.0 since then we changed
    __doPostBack to check for onsubmit before submitting the form.

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Feb 26, 2007
    #7
  8. Hi Velvet,

    I am interested in this issue. Would you mind letting me know the result of
    the suggestions? If you need further assistance, feel free to let me know.
    I will be more than happy to be of assistance.

    Have a great day!

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Mar 1, 2007
    #8
    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. Libs
    Replies:
    0
    Views:
    1,478
  2. Matt
    Replies:
    14
    Views:
    4,061
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  3. =?Utf-8?B?dmlkeWE=?=
    Replies:
    1
    Views:
    735
    Kevin Spencer
    Jun 2, 2005
  4. Boss302
    Replies:
    0
    Views:
    1,006
    Boss302
    Nov 21, 2006
  5. Velvet
    Replies:
    1
    Views:
    363
Loading...

Share This Page