How do you process forms.submit on the server side?

  • Thread starter Thread starter milkyway
  • Start date Start date
M

milkyway

Hello there,

I have the following code (written in Javascript) for posting of a form
on the client side:

....
var f2 = document.forms[SubmitForm];
f2.method = "post";
f2.submit();

When this goes to the server side, I tried to catch with:

public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
}
}
}

During the post, Page.IsPostBack is set to false.

What can I do to process the f2.submit() from the client side?

TIA
 
Milkyway,

Is there a reason that you have to submit the form via javascript? If you
just use a regular ASP.NET submit button then Page.IsPostBack will be set to
true...

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
You probably have to call the __doSubmit(...) (or something like that)
method.

There is additional information that gets sent to the server that the site
may look for such as viewstate.
 
Justin: I am using forms.submit() because my code is doing something
like the following

<INPUT onclick="alert('about to start'); process_table('ShadFrmX',
'FValues');" type="button" value="Continue" >

Basically, I have a another form (called ShadFrmX) in my HTML that
starts out as being empty. This form is filled with the execution of
process_table with values to be sent to the server.

After the form is filled, then I call the code above (although all of
it is not present) to submit the form to the server.

The form submission works. The values do come over. I have seen it in
the debugger :-) and have been able to save them in a file.

The thing is, I don't know what event I should process or function
module I should use on the server side to when I do a forms.submit() on
the client side. Someone said to use page_load and a flag IsPostBack
but this does not work :-(

Will a submit button run the javascript code I have?

Since I am new to this programming area - I was wondering what would be
the right way to process this.

Peter: Is there a place where I can get more information (hopefully a
sample) on how to use doSubmit()?

Thanks for the help!
 
milkyway,

Yes, you can call the javascript from a submit button. Then the script will
run, the form will submit, and the Page.IsPostBack value will be true.

You will want to remove the forms.submit() from your javascript and add
"return true;" so that the button will still submit the form.

Then hook up a call to your javascript from the button in the page load of
the code behind like this:

MySubmitButton.Attributes.Add("onclick",
"javascript:YourJavascriptFunctionHere();")


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
Hi Justin, Thanks for the pointer but I got things to work by using:

protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["Test"] != null)
{
//do processing with controls on the form
}
}

Is this something good/bad to? If so, why or why not?
Thanks!
 
milkyway,

That's a fine way to do it. It's really just a matter of how you like your
code structured/separated.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
Back
Top