Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted
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. I'm 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
3,450,897,223 posts away from crazy...
Posted
Heh...sorry...guess I could've 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
3,450,897,223 posts away from crazy...
Posted

Robby:

I took a look at the sample project you created, and it makes lots of sense. But in my case, I'm 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

3,450,897,223 posts away from crazy...
  • *Gurus*
Posted

I'd 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 you'll have to produce some God awful spaghetti code, decreasing efficiency and readability, and creating an application that is far from reliable. I've 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. Don't 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, you'll 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, you'll need to associate these values with what they represent. If the user input "John Doe" you'll 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 it's 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, that's your choice. Some people enjoy illness... :)

 

Someone else will be around to post an example, as I'm tight on time.

Posted

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... I've been battling with this silly issue all day long, and I just happen to be to the point where I'm trying to read the values from these dynamically-generated textboxes, and couldn't figure out from what controls collection to iterate through in order to read them. But, I think with your input regarding parent controls, I'll be in good shape. Chances are, ultimately I'll never use this dynamic-creation paradigm, but it's good to know what's 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

3,450,897,223 posts away from crazy...
Posted

Ok, apparently I'm spending entirely too much time on .NET. BUT, I'm 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 can't "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 don't have access to the .text property of the CTRL variable I've dimensioned. I assume this is because it's 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:

3,450,897,223 posts away from crazy...
Posted
Dude!!!! Derek!!! You're a genius, and I'm 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, I'm golden! Thanks again, all! :D
3,450,897,223 posts away from crazy...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...