How to determine where submit() was sent from???

  • Thread starter dandrew22 via DotNetMonster.com
  • Start date
D

dandrew22 via DotNetMonster.com

Hi all
I'm completely new to ASP.Net and need some help please.
I'm doing some client side validation using Javascript. The relevant code is
below:
<input type="button" value="submit" onclick='return checkDetails();' />

formObj = document.forms[0]; //refers to the current form.
formObj.submit(); //submits.

It then goes off to the Main_Load function (below) in the Default.master file
(I'm using a master page).
protected void Main_Load(object sender, EventArgs e)
{
//From here I aim to call various server side code behind files to do
the maths.
}

MY QUESTION IS how do I find out when I'm in the above function whether the
function was called from this submit or another submit elsewhere? Is there
a parameter I can send with the submit or something?? Hope I make sense and
thanks in advance.
 
G

Guest

MY QUESTION IS how do I find out when I'm in the above function whether the
function was called from this submit or another submit elsewhere? Is there
a parameter I can send with the submit or something?? Hope I make sense and
thanks in advance.

If you use a submit button instead:

<input type="submit" name="Startibarfast" value="submit" />

Then you can check if the form was posted using that button by checking if
the form data contains a value with the name of the button:

if (Request.Form["Startibarfast"] != null) ...

If you can's use a submit button, you can add a hidden field to the form,
and put some value into it before you post the form.
 
J

Jon via DotNetMonster.com

Thanks Guffa for you reply.

But using the type='submit' rather than type='button' causes the client side
validation to be skipped.
I need a way that once the button is pressed whether it be a submit or button
type the client side validation is called. Once the client validation has
completed the submit is then executed causing the Main_Load event to come
into play. Once in this event I need a way to check which submit actually
passed me to here?

I also need a way to pass values when submitting from javascript, or once in
the Main_load event reference the controls back on the form (the form being a
different aspx page) so I can get the controls values???

Hope I make sense - PLEASE HELP!!!
 
G

Guest

I need a way that once the button is pressed whether it be a submit or button
type the client side validation is called.

Put the validation in the onsubmit event of the form or in the onclick event
of the submit button:

onclick="return TheFunctionThatDoesTheValidation();"
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top