How use javascript with asp.net forms?

Discussion in 'ASP .Net' started by COHENMARVIN, Aug 5, 2005.

  1. COHENMARVIN

    COHENMARVIN Guest

    I have a problem that sounds simple but seems impossible with asp.net.
    I calculate a variable in the Page_Load event, call it X. Then I want
    my range validators to fire when a textbox value is greater than X.
    They should give an error message, both as a messagebox and inline in
    the page. I can't get the range validators to use X. I get syntax
    errors when I try. I tried Custom Validators and got the same problem.

    So now I want to try using client side javascript with forms. This may
    not work either, because I calculate X in page_load, and I don't know
    how to communicate X to the javascript. But forget that for now, does
    anybody know how to intercept the SUBMIT click of an asp.net form and
    use client side javascript validation on it?
    COHENMARVIN, Aug 5, 2005
    #1
    1. Advertising

  2. COHENMARVIN

    Alex D. Guest

    pass the X in a hidden field, but use Styles to hide the field, otherwise
    it wont pass any value. in javascript I guess you can use the events fired
    when moving away from the textbox and compare that to the hidden field.


    "COHENMARVIN" <> wrote in message
    news:...
    >I have a problem that sounds simple but seems impossible with asp.net.
    > I calculate a variable in the Page_Load event, call it X. Then I want
    > my range validators to fire when a textbox value is greater than X.
    > They should give an error message, both as a messagebox and inline in
    > the page. I can't get the range validators to use X. I get syntax
    > errors when I try. I tried Custom Validators and got the same problem.
    >
    > So now I want to try using client side javascript with forms. This may
    > not work either, because I calculate X in page_load, and I don't know
    > how to communicate X to the javascript. But forget that for now, does
    > anybody know how to intercept the SUBMIT click of an asp.net form and
    > use client side javascript validation on it?
    >
    Alex D., Aug 5, 2005
    #2
    1. Advertising

  3. COHENMARVIN

    Oliver Wong Guest

    Your post is a bit cluttered, with 3 problems embedded in it. I'll try
    to handle them one by one.

    "COHENMARVIN" <> wrote in message
    news:...
    >I have a problem that sounds simple but seems impossible with asp.net.
    > I calculate a variable in the Page_Load event, call it X. Then I want
    > my range validators to fire when a textbox value is greater than X.
    > They should give an error message, both as a messagebox and inline in
    > the page. I can't get the range validators to use X. I get syntax
    > errors when I try. I tried Custom Validators and got the same problem.


    Syntax error means you've typed in something which does not represent a
    valud ASP.NET program. If you posted some source code, someone might be able
    to find the syntax error and help you out with that.


    > So now I want to try using client side javascript with forms. This may
    > not work either, because I calculate X in page_load, and I don't know
    > how to communicate X to the javascript.


    You could output X as a hidden form input, e.g.:

    <INPUT TYPE="hidden" VALUE="[whatever the value of X is]">

    > But forget that for now, does
    > anybody know how to intercept the SUBMIT click of an asp.net form and
    > use client side javascript validation on it?


    I don't know of a clean way of doing this. It's possible, but would
    require lots of messy hacks, so you'd probably be better off with tackling
    one of the above two problems first.

    - Oliver
    Oliver Wong, Aug 5, 2005
    #3
  4. COHENMARVIN

    Peter Blum Guest

    I agree with Oliver, who suggests continuing to try to use the validators.
    There is no reason why you cannot get a CustomValidator to handle what you
    want.

    When you state you are calculating a value on the server side and using it
    with a RangeValidator, are you using that value as the Minimum or Maximum of
    the range? If so, there is no javascript involved. You convert the number to
    a string and assign it to one of those properties. The RangeValidator
    handles it from there. Just make sure RangeValidator.Type is Integer,
    Decimal, or Currency.

    Actually I notice that you want the textbox value greater than X. So lets
    switch from RangeValidator to CompareValidator. Set the Operator to
    GreaterThan and ValueToCompare to the string of the number you calculate.

    --- Peter Blum
    www.PeterBlum.com
    Email:
    Creator of "Professional Validation And More" at
    http://www.peterblum.com/vam/home.aspx

    "COHENMARVIN" <> wrote in message
    news:...
    >I have a problem that sounds simple but seems impossible with asp.net.
    > I calculate a variable in the Page_Load event, call it X. Then I want
    > my range validators to fire when a textbox value is greater than X.
    > They should give an error message, both as a messagebox and inline in
    > the page. I can't get the range validators to use X. I get syntax
    > errors when I try. I tried Custom Validators and got the same problem.
    >
    > So now I want to try using client side javascript with forms. This may
    > not work either, because I calculate X in page_load, and I don't know
    > how to communicate X to the javascript. But forget that for now, does
    > anybody know how to intercept the SUBMIT click of an asp.net form and
    > use client side javascript validation on it?
    >
    Peter Blum, Aug 5, 2005
    #4
    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. David Virgil Hobbs
    Replies:
    0
    Views:
    513
    David Virgil Hobbs
    Jan 6, 2004
  2. jlopes151
    Replies:
    2
    Views:
    625
    Steve C. Orr [MVP, MCSD]
    Mar 14, 2005
  3. M
    Replies:
    0
    Views:
    383
  4. Toni Pohl
    Replies:
    1
    Views:
    936
    Toni Pohl
    Aug 10, 2008
  5. Eric
    Replies:
    2
    Views:
    503
Loading...

Share This Page