Web Servers General Talk - How do you process forms.submit on the server side?

This is Interesting: Free IT Magazines  
Home > Archive > Web Servers General Talk > October 2005 > How do you process forms.submit on the server side?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

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

2005-10-05, 9:06 pm

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

S. Justin Gengo

2005-10-05, 9:06 pm

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
"milkyway" <d0mufasa@hotmail.com> wrote in message
news:1128550737.569456.160500@g49g2000cwa.googlegroups.com...
> 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
>



Peter Rilling

2005-10-05, 9:06 pm

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.

"milkyway" <d0mufasa@hotmail.com> wrote in message
news:1128550737.569456.160500@g49g2000cwa.googlegroups.com...
> 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

2005-10-06, 2:50 am

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!

S. Justin Gengo

2005-10-06, 7:53 am

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",
" Java script:YourJavascriptFunctionHere();
")


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche

"milkyway" <d0mufasa@hotmail.com> wrote in message
news:1128576990.261382.274310@f14g2000cwb.googlegroups.com...
> 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

2005-10-07, 2:57 am

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!

S. Justin Gengo

2005-10-07, 6:07 pm

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
"milkyway" <d0mufasa@hotmail.com> wrote in message
news:1128661508.893135.261350@g47g2000cwa.googlegroups.com...
> 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!
>



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com