Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form action not working? 1

Status
Not open for further replies.

csutton

Programmer
Dec 27, 2000
213
US
I have 2 aspx files. File 1 contains a form with runat=server. I manually typed the action to go to file 2 so I could process the results, but when file 1 runs, the action says to go to file 1. I cannot find anything that says whether or not this is correct behavior.

My situation is: file 1 contains a search form with a bunch of yes/no options and an area for an SQL inquiry. I want file 2 to parse the results of file 1 and display the reults of the search. I did not think it would be a smart idea to do a response.redirect w/the parameters on the URL line. Any other options?!?!?!?! Thanks.
 
Yes, well, sorta.. Visual C# Standard Edition.
 
k, well here's one idea you could do that would eliminate the response.redirect issue entirely:

Create a .vb file in the project (or create a seperate dll if you want an entire middle "logic" tier) and create a class that will hold all the values that you want to evaluate on page 2.

In your page one code, when the user clicks OK or whatever the button is, in the click event for the button in the code behind create an instance of the object, fill it with the details, and assign it to a session variable.

Then, response.redirect to page 2 but don't pass anything in the url. When page 2 loads, in the code behind you can access the session variable storing your object, do your voodoo to the data, and display the results.

VOILA!

One option anyway.
:)

Jack
 
Thanks Jack, I'll try to see how it works out.
 
sorry... but why don't you just simply use the :

System.Web.HttpServerUtility.Page.Server.Transfer(URL);

this way... no one could see the query string you send to page 2.

anyway, there's is another way that i think is a better way... you just simply add another :

<form method=&quot;post&quot; action&quot;page2url&quot;>
<input type=&quot;textbox&quot; name=&quot;blabla&quot;>
<input type=&quot;submit&quot; value=&quot;blbla&quot;>
</form>

this will simply post your search &quot;OK&quot; button to page 2

well, i prefer second way, coz it reducing the server object... you know the runat=&quot;server&quot; could reduce your system's performance up to 15 % (this is what i read, but i haven't tried it yet ^-^)
 
Hey Ja,

Good suggestions. A few questions though:

1. System.Web.HttpServerUtility.Page.Server.Transfer(URL) just terminates the current processing and redirects to a new url. However, if he wanted that new page to get the info, he'd STILL have to pass in in the url string with the parameters attatched, meaning that when the page loads it would STILL have the information showing (which is what he wanted to avoid), correct?

2. I agree with your second suggestion, however in csutton's first post, he stated that he was having trouble doing it that way and wanted other options. So, he could do your suggestion, BUT:
- a Request object still gets created, and his page 2 code will still have to use asp.net code that runs off the server to access the request items
- he'll also need page code that will create more objects to carry out the db connection, execute the query, sort the results, and pass them back in a way that will display nicely. This will add alot of unnecesarry bulk to his page

Or, he could do it my way:
-Creates and fills an object that encapsulates all the logic needed to retrieve the data, connect to the db, sort the results, and return them nicely. Stores in session
-New page loads, object data is binded to data-grid or whatever control he's using, object is destroyed. Page stays clean of code.
-If he ever needs to duplicate the functionality, instead of copying a page full of code, he just creates another object.

I see where you're coming from with the idea of keeping the server as un-busy as possible, but good code design shouldn't be sacrificed; especially with a technology thats meant to run as a second-generation mainframe architecture.

Just MHO though.

Jack

 
Thanks guys,

What I ended up doing (for now until I learn more about the encapsulation, etc) is when it posts back, I create the SQL string required to do the search, and set the session variable to carry that sql string, then just redirect the user to page 2, where it checks to see if the session variable exists and executes it accordingly.

I do like Jack's idea and plan to implement that more fully, but when time permits :)

Thanks again!!
Chris
 
wahhh i'm sad ):

just kidding ^-^... it's good to use layering (logic tier), actually, i also prefer it that way... middle tier and session... that really made our life as a programmer become easier :)... BUT there's one article i read 'bout session and web farming... as you know the session object is stored in the web server... as long as your client access the same server... the session remains the same, but if your company apply web farming, which means several servers for the web server... then the session in one server couldn't be shared to another web server. Anyway, i haven't tried it yet :) i've just read the article :)

Actually, besides session, there's another object to store your information... it's VIEWSTATE, which is only available at ASP.NET, BUT the information is stored on your client (it's attached to the page)

Anyway, it's up to you to choose whether to use session or viewstate... but i really agree to jfrost suggestion to use middle tier logic... i always use that too :)
 
aloha jfrost :), i'll try to clear your questions :

1. System.Web.HttpServerUtility.Page.Server.Transfer(URL) just terminates the current processing and redirects to a new url.
-> that's right (the first page thread is aborted)
However, if he wanted that new page to get the info, he'd STILL have to pass in in the url string with the parameters attatched, meaning that when the page loads it would STILL have the information showing (which is what he wanted to avoid), correct?
-> there's two way to do this... first, you could just store it all in the query string, AND your querystring won't show up in the address bar... what's shown in your browser's address bar is your 1st page url, just try it :)
the second way, you could store your information in your first page as a properties as an example, then in the second page you could access your first page by using :
((1stpageclass)this.FindControl(&quot;yourfirstpage.aspx&quot;)).YourProperty
anyway, i don't like the second way, it's much too confusing and just like you do, i don't like the page full of code, i prefer do the logic for searching using middle tier.

2. I agree with your second suggestion, however in csutton's first post, he stated that he was having trouble doing it that way and wanted other options. So, he could do your suggestion, BUT:
- a Request object still gets created, and his page 2 code will still have to use asp.net code that runs off the server to access the request items
-> a request object is ONLY created when the input type submit button is clicked. if you create the page full of server object, they're always created when the page is loaded, eventhough we don't use them all.
- he'll also need page code that will create more objects to carry out the db connection, execute the query, sort the results, and pass them back in a way that will display nicely. This will add alot of unnecesarry bulk to his page
-> we could reduce the complexities of the page code using two ways...
the first way... in your second page... you could just parse the request.params object and pass it on to the logic tier to do the searching and return the result as an arraylist or whatever... this way, your page will be clean too :)
the second way... you could just simply made the search module to be a web user control... then all the logic is handled by the user control... your 1st page simply attached your &quot;search user control&quot; if you want your page contain a search module. This way, every page you want to have a search module, simply attach the user control, then it's there :)

anyway, it's nice to have a response from you jfrost :)... this forum is what i dreamt of :)... full of responses :) could i know your email? perhaps we could share knowledge, troubles (if you don't mind ^-^), etc
 
Wow, look at this threading I've started :) hehehe. Thanks again both of you for your posts.. been very helpful!
 
Tsk tsk, there goes Sutton starting trouble in the forums again!
;)
Just kidding man, glad we could help.
:)

Yeah ja, that would be kewl man. My email is
jfrost10@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top