getting info out of a form's submit method

  • Thread starter Thread starter PJ6
  • Start date Start date
P

PJ6

When I have client-side script like this -

document.forms[0].submit('test')

how do I access, from server-side code, the value I put in the submit
method?

Also, is it possible to get the control's containing form name so I can
emite script like this -

document.SomeFormName.submit('test')

so I don't have to assume it's in forms[0]?

Paul
 
1) document.forms[0].submit('test') is an invalid syntax.. If you are looking
to send some additional value to server code, one common method is to use a
HTML Hidden Control or a TextBox Webcontrol with size 0.. In the code behind,
you could access the hidden control like Request.Form["HiddenCtrlName"]
..ToString();

2) document.SomeFormName.submit(); is a valid syntax.
 
I have a control that I want to act like a button. I cannot assume that the
containing page has a hidden control. I'm looking for a way to get the
client-side OnClick event to cause the server-side control event to fire.

Paul

Sreejith Ram said:
1) document.forms[0].submit('test') is an invalid syntax.. If you are
looking
to send some additional value to server code, one common method is to use
a
HTML Hidden Control or a TextBox Webcontrol with size 0.. In the code
behind,
you could access the hidden control like Request.Form["HiddenCtrlName"]
.ToString();

2) document.SomeFormName.submit(); is a valid syntax.


PJ6 said:
When I have client-side script like this -

document.forms[0].submit('test')

how do I access, from server-side code, the value I put in the submit
method?

Also, is it possible to get the control's containing form name so I can
emite script like this -

document.SomeFormName.submit('test')

so I don't have to assume it's in forms[0]?

Paul
 
2) " to get the control's containing form name "

One way i could think of is, you could get the parent control recursivly
until the parentElement.tagName == 'FORM'

I m writing below code on the fly... havent tested.. but hope it gives an
idea..

<script>
notFound = false;
ParentElem = document.getElementById("bttonName").parentElement;
while(notFound == false)
{
if(ParentElem.tagName == 'FORM')
{
//Now ParentElem is the FORM containing the control
// you my exit the loop and call ParentElem.Submit();
document.writeln(ParentElem.id);
notFound = true;
}
else
ParentElem = ParentElem.parentElement;
}
</script>

this should work, but you will be able to come up with a more efficient
recursive script for the same.. probably you will find a sample in
blogs/sites

1) not sure i have understood the requirement... When you say " I have a
control that I want to act like a button" , is that a webcontrol or a user
control?.. if user control, you could still have a hidden control next to the
button/image/link you are expecting the user to click..



PJ6 said:
I have a control that I want to act like a button. I cannot assume that the
containing page has a hidden control. I'm looking for a way to get the
client-side OnClick event to cause the server-side control event to fire.

Paul

Sreejith Ram said:
1) document.forms[0].submit('test') is an invalid syntax.. If you are
looking
to send some additional value to server code, one common method is to use
a
HTML Hidden Control or a TextBox Webcontrol with size 0.. In the code
behind,
you could access the hidden control like Request.Form["HiddenCtrlName"]
.ToString();

2) document.SomeFormName.submit(); is a valid syntax.


PJ6 said:
When I have client-side script like this -

document.forms[0].submit('test')

how do I access, from server-side code, the value I put in the submit
method?

Also, is it possible to get the control's containing form name so I can
emite script like this -

document.SomeFormName.submit('test')

so I don't have to assume it's in forms[0]?

Paul
 

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

Back
Top