Home > .NET, ASP > ASP .NET Nested Forms (Or why do I get the error ‘Invalid postack or callback argument’)

ASP .NET Nested Forms (Or why do I get the error ‘Invalid postack or callback argument’)

I have now come across a few situations where using nested forms in ASP .NET causes problems. The typical error produced in this case is a ‘Invalid postback or callback argument’ error. This occurs because ASP .NET allows the rendering of multiple, nested forms but fails to validate the forms when a postback occurs. Thus when ASP .NET recognizes nested forms in a page, it marks the page as not valid (Page.IsValid returns false).

The reason that this error occurs is because multiple, nested forms cannot reside on a single aspx page .

The solution is very simple: The submit button for the user created form must contain the following attribute: onclick=”this.form.submit();”. A recent example I came across is below. The basic form that was developed and placed inside an aspx page as a nested form was as follows (only the beginning and ending of this form is shown. The content is not necessary or relevant):

<form accept-charset=”UTF-8″ action=”http://www.response-o-matic.com/mail.php&#8221; method=”post” enctype=”multipart/form-data”>

                <table>

                                <tbody>

                                                .

                                                .

                                                .

                                                .

                                                <tr>

                                                                <td colspan=”2″ align=”center”>

                                                                                <input value=” Submit Form ” type=”submit” />

                                                                </td>

                                                </tr>

                                </tbody>

                </table>

</form>

The following code demonstrates the proper way of entering this form so that nested forms will work. Please note that I reiterated all of the attributes (action, method, enctype, etc…) of the form in the JavaScript call.

<form accept-charset=”UTF-8″ action=”http://www.response-o-matic.com/mail.php&#8221; method=”post” enctype=”multipart/form-data”>

                <table>

                                <tbody>

                                                .

                                                .

                                                .

                                                .

                                                <tr>

                                                                <td colspan=”2″ align=”center”>

                                                                                <input onclick=”this.form.action=’http://www.response-o-matic.com/mail.php&#8217;; this.form.method=’post’;this.form.enctype=’multipart/form-data’;this.form.submit();” value=” Submit Form ” type=”submit” />

                                                                </td>

                                                </tr>

                                </tbody>

                </table>

</form>

Advertisements
Categories: .NET, ASP
  1. Yep
    April 1, 2008 at 12:53 am

    Does not seem to work.

  2. relic411
    April 1, 2008 at 11:32 am

    Really? What sort of problem are you having with it? Could you post your code?

  3. May 2, 2009 at 1:55 pm

    Thanks, works well

  4. zak
    February 4, 2010 at 12:06 am

    Hey Relic, I am using this code to alter a piece of code that I have to add to an asp.net page in blogengine. Your method seems to work aside from one problem I am having. They simply want the form to open a new page for a customer sign up form. The way I have used your code, causes the original page to go to the sign up form (which I do not want to happen), and also opens a new window going to the same sign up form. Any ideas? Here is my code:

    <img src="../Images/hdrConnectShare.png” width=”280″ height=”14″ alt=”” />
    Sign up to be on our emailing list and get exclusive content and merchandise offers.

  5. zak
    February 4, 2010 at 12:07 am

    not sure why the code didn’t display

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: