Collecting form data when there is not a submit button

A

antonyliu2002

I have 4 forms each on a separate page respectively form1.aspx,
form2.aspx, form3.aspx, form4.aspx.

On top of each of the four pages there are 4 links which link to the
aforementioned 4 pages like this:

Form1 Form2 Form3 Form4

Important: Only form4.aspx has a submit button, none of the other 3
forms has any kind of submit or 'next step' button.

So, how can I collect the data from, say, form1, when the user clicks
the link Form2 or Form3 or Form4 to continue?

I know that I can use session for this case, but the problem is, since
there is no submit button on form1, form2 and form3, what triggers the
action of data-collection from these 3 pages when the user leaves them
by clicking the links at the top of the page?

I don't think there is an onLeave function, is there?

Any idea? Thanks a lot!
 
S

S. Justin Gengo

Make your links into LinkButton objects which will post back the page. Then
do any page processing you need to and use the Response.Redirect method to
send the client to the next page.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
A

antonyliu2002

Hey, Justin,

This sounds cool! I will absolutely try it out. By trying it out, I
mean that I don't yet know how to do it, but with your hint, I think I
can probably figure it out. Thanks a lot!
 
S

sreejith.ram

Another method would be to use 4 ASP:pANELs in a single page and hide
and show each of them(using javascript) upon clicking the form names.

The advantages are that
1) This method require only 1 database post
2) You dont need any special logic/temp table to display the data
already entered by user in the previous form
3) No partially saving data ,when the user never actually submitted.
(could be a disadvantage too if u plan to save partial data)
4) No page refresh required while changing between forms

only an option if you could afford to redesign the pages and if the
current forms are not too complex.

If interested try google on ASP:pANEL .. i remeber seeing a very good
article with code on how to use panels to achive this.
 
A

antonyliu2002

Yes, I've heard of this option, too. But I think it is kind of
difficult to implement, especially when you want it to be compatible
with most major browsers.

I have implemented the LinkButton approach Justin offered. It works
great! Thx.

That said, I have one more little problem.

Say, on form1.aspx I have:

*************************
Form1 | Link_to_Form2 |
------------------------

First name: ___________
*************************

On form2.aspx I have:

*************************
Link_to_Form1 | Form2 |
------------------------

Last name: ___________
*************************

Sure, nobody will develop a site that looks like this, but just so that
I can make the problem clear.

Now, if the user has filled up his first name on form1.aspx, he then
clicks on Link_to_Form2 and continues to supply his last name on
form2.aspx.

I want these two pages to be able to retain the user-supplied data, so
that once the forms have been filled, the information will always be
there no matter how many times the user clicks Link_to_Form1 or
Link_to_Form2.

I know that this will work if the user just clicks the "back" or
"forward" buttons on most browsers (mostly graphically represented by
<- or -> ).

Right now, my application does not work as I want. If the user goes to
either of the two pages by clicking on the LinkButtons I supplied, the
information they gave is gone.

I also know that I can achieve my goal by storing the information in a
session variable and then retrieve it from the session variable. But
is there an easier way to handle this?
 
S

S. Justin Gengo

An easier way than storing the information in the session variable? No, I
think that's the easiest way.

But there are other ways to do this. One way would be to store the
information in the Page.Context object and use Server.Transfer to move from
one page to the other.

That would look something like this:

Page 1:

Context.Items.Add("FirstName", FirstNameTextBox.Text)
Server.Transfer("page2.aspx")

Page 2:
'---On page load store the FirstName in viewstate.
Dim FirstName As String = Context.Items.Item("FirstName").ToString
ViewState.Add("FirstName", FirstName)

'---LinkButton Postback on page two returns to page 1
Context.Items.Add("FirstName", ViewState.Item("FirstName").ToString
Server.Transer("page1.aspx")

'---Back on page 1 check if first name already exists in context
If Not Context.Items.Item("FirstName") Is Nothing Then
FirstNameTextBox.Text = Context.Items.Item("FirstName").ToString
End If


As you can see this is a little more complex than using session variables.
But if you don't want to be reliant on the session this would be a good way
to go.


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top