The best method for passing parameters from ASP page to ASP page...

Daspoo

Well-known member
Joined
Jan 27, 2003
Messages
99
Location
Fort Walton Beach, Florida
I know this can turn out to be entirely based on personal preference and opinion, but does anyone know which is the most practical AND efficient method of passing parameters from one ASP page to another. Im working on a project which will be using a Crystal Reports Viewer object, and after prompting the user for parameters for the report he/she wishes to view, I would like to pass those params to the page holding the viewer. Thanks in advance for the help.:D
 
Heh...sorry...guess I couldve been more descriptive. After the user selects a report (from a radio button list of reports), he will click a button to prepare the report. That button will call the parameters page which will be dynamically built with labels and textboxes for the parameters (back to my most recent post) for the selected report. The user will then enter the appropriate info into the textboxes, and once done, will then click another button to load the report, which will go to the final page, which contains the Crystal Viewer. Going to that last page, I need to determine what the best method of passing those parameters (entered by the user in the textboxes) would be. Hope that clears it up...sorry. :p
 
Robby:
I took a look at the sample project you created, and it makes lots of sense. But in my case, Im going to have textboxes dynamically created, and the number of textboxes will be dependent on the number of parameters necessary for the Crystal report. So, setting properties is not going to be much help if the number of properties required changes from report to report. And, assuming I get that all worked out, how will I be able to dynamically determine what property to call for my dynamic parameters? In other words, if I have 2 parameters, the project has to somehow a) know to create two distinct readonly properties, and b) it has to know to iterate through its count of parameters and read the correct property:

(as in, dim sourcepg as new webform1

for i=0 to 1
parameterValue = sourcepg.property(i)
next )

Am I totally complicating the issue, or am I just way off my rocker? Thanks in advance for the help, and for simply taking the time to read my madness...:D
 
Even if their created at RT, you can itterate the controls and get their values.

Ill see if I can test something out.
 
Id strongly suggest reconsidering the use of dynamically created controls. Any programmer, regardless of the language he or she uses, will warn you against doing this. More often than not youll have to produce some God awful spaghetti code, decreasing efficiency and readability, and creating an application that is far from reliable. Ive yet to see one situation where dynamically created controls are absolutely needed, whether it was in regards to a Windows application or a web page. There has always been another solution, and I doubt this is any exception. Just keep that in mind.

If you do insist on going ahead with this, look into creating parent controls for each set of like textboxes or labels. Dont mix control types inside one parent, as this is only going to lead to pain and heartache later on. The key here is to restrict the dynamic controls to their own sad little world, not letting them affect their static counterparts. Of course, once the data is submitted, youll need to retrieve and process it somehow. Do this by looping through the Controls collection of the parent object that contains the controls whose value you need to read. As I said before, keeping the dynamic controls separate will make this part of the process rather easy.

Continuing on, youll need to associate these values with what they represent. If the user input "John Doe" youll obviously need to feed that into the associated variable that requires that data... and so on an so forth for each control. Now, you can choose to associated each control to its associated variable via its Tag property or by parsing each bit of incoming data and determining where it belongs. This is the part that gets ugly, and the very part that makes any sane human being want to avoid the idea of dynamically controlled input like any decent human being would want to avoid the plague. But hey, thats your choice. Some people enjoy illness... :)

Someone else will be around to post an example, as Im tight on time.
 
Derek:
Thanks for your feedback. Good thing I checked this before leaving the office. Guess I have homework to do after all - research on using parent controls... Ive been battling with this silly issue all day long, and I just happen to be to the point where Im trying to read the values from these dynamically-generated textboxes, and couldnt figure out from what controls collection to iterate through in order to read them. But, I think with your input regarding parent controls, Ill be in good shape. Chances are, ultimately Ill never use this dynamic-creation paradigm, but its good to know whats going on regardless. Being a "raw newbie" to ASP.NET - and VS.NET in general, I can use all of the extra knowledge I can get. Thanks for your assistance! :D
 
Ok, apparently Im spending entirely too much time on .NET. BUT, Im at the point where I have my dynamic textboxes appearing as they should, and as Derek warned me about, I now am attempting to pull data from the .text properties of the textboxes. When I attempt to iterate through the placeholder containing these textboxes, I cant "use" the text property...in other words:

======================================
Dim ctrl as Control

For Each ctrl In PlaceHolder1.Controls
If TypeOf ctrl Is TextBox Then
If ctrl.ID = "txtParams" & j.ToString Then
Return (ctrl.text)
End If
End If
Next

I dont have access to the .text property of the CTRL variable Ive dimensioned. I assume this is because its seeing this as a control and not a webcontrol? But, if I redimension it as a webcontrol, then I receive a cast error like the following:

=======================================
Server Error in /WebAppCrystalRevisit Application.
--------------------------------------------------------------------------------

Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:

Line 114: Public ReadOnly Property GetParam(ByVal j As
Integer) As String
Line 115: Get
Line 116: For Each ctrl In PlaceHolder1.Controls
Line 117: If TypeOf ctrl Is TextBox Then
Line 118: If ctrl.ID = "txtParams" & j.ToString Then Return (ctrl.ID.ToString)


Source File: c:\inetpub\wwwroot\WebAppCrystalRevisit\frmParameters.aspx.vb Line: 116
=======================================

Anyone have any comments about this? Does anyone agree with Derek and can offer an alternate means by which I may accomplish the goal of this cwazy exercise? Thanks in advance. :cool:
 
Dude!!!! Derek!!! Youre a genius, and Im just plain *ahem*... :) Something SO simple and yet EXACTLY what I was looking for. Thanks for all of your help and everyone else who took the time and interest to participate in this newbie experience. heh... I think this gets me where I need to be, so as far as "this" post goes, Im golden! Thanks again, all! :D
 
Back
Top