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

Discussion in 'ASP .Net' started by milkyway, Oct 5, 2005.

  1. milkyway

    milkyway Guest

    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, Oct 5, 2005
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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, Oct 6, 2005
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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, Oct 6, 2005
    #3
  4. milkyway

    milkyway Guest

    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, Oct 6, 2005
    #4
  5. 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

    "milkyway" <> wrote in message
    news:...
    > 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, Oct 6, 2005
    #5
  6. milkyway

    milkyway Guest

    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, Oct 7, 2005
    #6
  7. 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" <> wrote in message
    news:...
    > 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, Oct 7, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    14
    Views:
    4,169
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  2. The Crow
    Replies:
    2
    Views:
    4,441
    Bruce Barker
    Sep 27, 2005
  3. Joey
    Replies:
    1
    Views:
    804
    =?Utf-8?B?aGVpbg==?=
    Jan 3, 2006
  4. Replies:
    4
    Views:
    980
  5. Replies:
    3
    Views:
    750
Loading...

Share This Page