|
-
Jan 1st, 2012, 01:06 PM
#1
Thread Starter
PowerPoster
Declaring a code-behind variable for Javascript?
What I am trying to do, is perform some edit checks on required fields in my page. When the "Submit" button is clicked, I wish to check execute a javascript function that does these checks.
The way I'm envisioning it is to declare a server-side variable in my VB.Net code-behind, set this value in the javascript CheckEdits() function and then back in the code-behind in the btnSubmit_Click() Event, check this variable.
Problem is...I'm not sure how to declare a code-behind boolean variable that can be checked in a javascript function. Any ideas?
Thanks,
-
Jan 1st, 2012, 04:59 PM
#2
Re: Declaring a code-behind variable for Javascript?
You could do it using Ajax, if the validation absolutely must be server-side. However, if the checks are simple "required" or "numeric" and the like, you can do that in JavaScript without the need for messy server-side checks. Which one do you need?
-
Jan 1st, 2012, 05:03 PM
#3
Thread Starter
PowerPoster
Re: Declaring a code-behind variable for Javascript?
Well, I the fields to be validated upon clicking the "Submit" button. So it sounds to me like it would be server-side validation. Doesn't a button, when clicked automatically make a request to the server? I would like to be able to click this button and process it using the client only. All this form does is validate some input and then sends an SMTP email (which I haven't gotten to work yet).
Thanks,
-
Jan 1st, 2012, 05:11 PM
#4
Re: Declaring a code-behind variable for Javascript?
Not necessarily. JavaScript can easily override form submit events. What are your validation criteria? Whether you can do this client-side depends on that.
-
Jan 1st, 2012, 11:33 PM
#5
Thread Starter
PowerPoster
Re: Declaring a code-behind variable for Javascript?
The form consists of 5 fields:
1. Users Name
2. Organization Name
3. Users Email Address
4. Subject
5. Memo/Note
All 5 fields have to be filled out. Pretty simple validation!
-
Jan 2nd, 2012, 04:01 PM
#6
Re: Declaring a code-behind variable for Javascript?
Here's an example of how to do that. Note that you shouldn't use alerts to tell people that a field is missing, however - that's just a demo. If you don't know JavaScript, you should find a good tutorial online or a book, and you can also get help in the right forum for this, which is Web Development
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|