![]() |
How use javascript with asp.net forms?
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? |
Re: How use javascript with asp.net forms?
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" <cohenmarvin@hotmail.com> wrote in message news:1123252630.034839.146320@g44g2000cwa.googlegr oups.com... >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? > |
Re: How use javascript with asp.net forms?
Your post is a bit cluttered, with 3 problems embedded in it. I'll try
to handle them one by one. "COHENMARVIN" <cohenmarvin@hotmail.com> wrote in message news:1123252630.034839.146320@g44g2000cwa.googlegr oups.com... >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 |
Re: How use javascript with asp.net forms?
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: PLBlum@PeterBlum.com Creator of "Professional Validation And More" at http://www.peterblum.com/vam/home.aspx "COHENMARVIN" <cohenmarvin@hotmail.com> wrote in message news:1123252630.034839.146320@g44g2000cwa.googlegr oups.com... >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? > |
| All times are GMT. The time now is 11:13 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.