multiple forms on the same page?

  • Thread starter Thread starter Gorge Lucas
  • Start date Start date
G

Gorge Lucas

Hi all,

How is it possible to have multiple forms on the one page. You have the main
form correct, but what if I need to post some data somewhere else? I have a
newsletter signup on the same page with server controls. It needs to be
submitted to a different website but it doesn't seem to work. I am guessing
this is because of having two forms on the single page. If there is no way
around this, in the postback, how is it possible to send this data to the
page I was trying to post to originally?

Thanks
 
Mark Rae said:
This is a common misconception. You can have as many <form /> objects in
an aspx page as you like - however, you can have only one server-side
<form runat="server" /> object. Multiple forms are very common e.g. in
sites which incorporate a payment gateway such as PayPal.

Ok, so the submit button, should this be a server control. For the second
form? Because currently it's not posting back.

The code is very simple:

<form action="http://someotherwebsite.com" method="post">
<div>
<label for="name">Name:</label><br /><input type="text" name="cm-name"
id="name" /><br />
<label for="gtke-gtke">Email:</label><br /><input type="text"
name="cm-gtke-gtke" id="gtke-gtke" /><br />
 
Mark Rae said:
Er, but you don't want it to post back, right? Unless I've misunderstood,
you want it to post to the remote site...

Yep, and the only way I got it working was to make the submit button a
server control. I then put it's postback url to the external url. Seemed to
work fine. I was wondering though, is it possible to post back that
information to the site, without going to the site. The site in question
displays a thank you page. I want to submit the info, but then do some stuff
on my site, like, move to a new view in a view control or something?
 
Mark Rae said:
I'm not sure what you're doing... The code you supplied was for an HTML
form, not an ASP.NET form...

As I said, you can have as many HTML forms on an ASP.NET page as you like.
Obviously, they won't run server-side, so none of the controls within them
can be server controls...

Ok, to clear it up. As it was, it was not posting data. Testing it locally,
it was posting back to Default.aspx, even though the form code was suppose
to be posting elsewhere. Once I changed the submit button to have a postback
url of what I was trying to achieve originally in the form code, it
worked...

So now it is posting the data to the url specified in the postbackurl. What
I want to know now is, can I post that information to the postbackurl
without having the client redirected there.

So maybe posting back to the Default.aspx, checking to see if it was the
newsletter that was being posted back, submit the data to external url,
change view on Default.aspx.

Does that make sense?
 
Back
Top