Post to another page (MasterPage, In JavaScript)

C

Cat

Suppose there are two pages X and Y. X,Y both uses the master page M,
and content area x, y.
X=M+x
Y=M+y

I want to post a form from X to Y. X is just an input form, so it
validate all the inputs in the JavaScript and the form's ACTION is set
to Y. But the problem is, that somehow the content area of X and Y are
surrounded with a FORM generated by ASP.NET. I think ASP.NET replaces
the content area with a FORM.

I created a form in the page x, but I think the form is somehow merged
with the form that is generated by ASP.NET. The form also adds a
_VIEWSTATE input, so when the form is posted this field is also
posted.

<form ...> <-ASP.NET generated one
<input type="hidden" name="_VIEWSTATE"...>
<form action="Y.aspx"...> <-I wrote
...
<input type="submit"/>
</form>
</form>

When the submit button is clicked it's not posted to Y.aspx, but the
form genereated by ASP.NET gets posted. I could replace the ACTION of
the ASP.NET generated form with JavaScript but the _VIEWSTATE causes
an exception when posted to another page.

I've searched MSDN and found a solution about posting to another page.
That page explained how to do it with controls like Button, Link and
so on. But in reality, we usually check form with JavaScript before
post. Posting the form with just a Button click is impractical.

How can I solve this situation? More specifically, I'd like to 1)
remove the auto-generated form for content area or 2)post only the
form I created not the outer form or 3) remove the _VIEWSTATE field.
 
G

Göran Andersson

Cat said:
Suppose there are two pages X and Y. X,Y both uses the master page M,
and content area x, y.
X=M+x
Y=M+y

I want to post a form from X to Y. X is just an input form, so it
validate all the inputs in the JavaScript and the form's ACTION is set
to Y. But the problem is, that somehow the content area of X and Y are
surrounded with a FORM generated by ASP.NET. I think ASP.NET replaces
the content area with a FORM.

No, a content area itself doesn't result in any html code at all. If
there is a form tag in the generated page, there is a form tag in the
markup code.

Check if there is a form tag in the master page.
I created a form in the page x, but I think the form is somehow merged
with the form that is generated by ASP.NET. The form also adds a
_VIEWSTATE input, so when the form is posted this field is also
posted.

Form tags can not be nested, so your form tag will simply be ignored by
the brower.
 
B

bruce barker

Webforms don't really support this model. they are designed for postback to
the same page. the action can only be changed with javascript (even setting
the postbackurl of a button is done with javascript).

you could switch to the MVC handler (still beta though), which is designed
to handle what you are doing, and is probably a better choice.


-- bruce (sqlwork.com)
 
G

Göran Andersson

bruce said:
Webforms don't really support this model.

It doesn't have to, as html does. The OP is using a regular htlm form,
not a ASP.NET server control form.
 
C

Cat

It doesn't have to, as html does. The OP is using a regular htlm form,
not a ASP.NET server control form.

This is a big problem then. The containtarea should be surrounded by a
form (or an exception is thrown), and forms cannot be nested. For
example, if I want to insert a PayPal button which uses a form posted
to the PayPal server, PayPay said that all In eed to do is to copy and
paste the code, but pasting that into a contentarea doesn't work
because two forms get nested. ASP.NET's form is always confusing and
make things complicated...

As a workaround I inserted an iframe, which is a simple .html file,
into the contentarea, then pasted the PayPal code into the .html file,
set target="_top" for the form. It worked anyway.
 
G

Göran Andersson

Cat said:
This is a big problem then. The containtarea should be surrounded by a
form (or an exception is thrown),

Which exception? I'm pretty sure that a content area doesn't have to be
inside a server form...
 
C

Cat

Which exception? I'm pretty sure that a content area doesn't have to be
inside a server form...

Ah. I was confused. I tested again and found that it was because the
content page contained ASP.NET controls. When I created master/content
pages within a WYSIWYG tool, it added a server form at the master
page, and none for the content pages.
Thank you for pointing out.
 

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

Top