Saturday, March 24, 2012

What is the best way of Form Processing?

Hi,
I am new to ASP.Net development. I am using ASP.NET 1.x
Problem:
I have a page which takes user input and then displays the results in another page.
To accomplish this in classic ASP way. I would create 2 pages. Page1.asp and Page2.asp and when the user clicks on Submit button on Page1.asp I will post the values to page2.asp and process them in this page.
With .Net as I cannot post to different page what is the best way to accomplish this?
(I don't want to pass the values as a query string to another page as it has limitations.)
Method1: I will use only one page. I will have 2 panels. On 1st panel I will add all the user input controls and on the second panel I will have controls to display the processed information. So the first time I will hide panel2 and just display panel1. When the user clicks on the submit button then I will hide panel1, process the values and display them on the controls in panel2 and make this visible.
Method2:In this method I will have 2 pages. page1.aspx and page2.aspx. In page1.aspx I will have all the user input controls and I will have public properties for each one of these input parameters. And in the ButtonClick event I will do a Server.Transfer to page2.aspx. In page2.aspx I will use Context.Handler to get the input values.
Refer to this article:http://www.codeproject.com/aspnet/DataPassingBtPages.asp
But I heard Server.Transfer causes lot of problems.
So is there a better way to accomplish this? If not which method is better to accomplish this.
Thanks
maximus_vj

although I am new as well, its my understanding that the best way is through panels. Rather than push info between different pages, all of your variables remain accessible by using panels and just one form. This is one of the main benefits of .net..having the data bound to the controls rather than posting input.

I'm not sure what the absolute best way of performing this is, but what I did is, in the submit event (mine is a link button click) I process the information and attempt to enter information into the database. If it successfully inserts, it then adds the necessary values to my Session object (only about 6 or 7 values in this case) and then performs Server.Transfer("page2"). Page2 is a confirmation page that spits back some of the information they entered along with a confirmation number and other appropriate information. I get all of this from the Session object.
The biggest advantage I see for the paneled approach is that all the page objects are created when the first page is created, some of them just aren't displayed in the HTML. So, when the postback/submit event fires it doesn't need to create new objects, simply use the ones it created previously.


I'm curious what the problems are with Server.Transfer(). You have described its usage pretty well. All you need to do is be sure:
1. The control objects defined on page1.aspx are Public so you can access them from outside of Page1.
2. You run validation in Page1 in the post back event handler (the Click method of a button for example) prior to calling Server.Transfer.

0 comments:

Post a Comment