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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send a DataSet to another Webform 1

Status
Not open for further replies.

christheprogrammer

Programmer
Jul 10, 2000
258
CA
Happy Monday...
So I have a DataSet which has its table(0) populated by a user-defined query on a webform. Now, I want to include a "Save results as Text File" button which will launch a standard "Save Text File" form which will have many options on it. But I want to pass this form the datatable that the user's query filled, and I want the "Save Text File" form to be independent of the other form (for re-use).

How?

Thanks Chris
 
Create a Session varaible where to store the DataTable:
in c#:

form1
Session["MyDataTable"] = dt; //or dataset


form2
DataTable dt = (DataTable) Session["MyDataTable"]; //or Dataset

hth
 
THANK YOU! I had no idea about session variables until you posted back. I learned all about them, and can't believe I was writing ASP.NET pages without knowing about this.

Cheers & thanks again Chris
 
You can also convert the dataset to an XML string and pass it to the next page as a querystring:

strData = objDataSet.GetXml()

Response.Redirect("NextPage.aspx?DSet=" & strData)


The receiving page ("NextPage.aspx") can recreate the dataset as follows:

Dim strXML as String = Request.QueryString("DSet")

Dim objDataSet As New DataSet("objDataSet")

Dim strReader As New System.IO.StringReader(strXML)

objDataSet.Readxml(strReader)

This approach sometimes works better when dealing with web farms.
 
I guess the XML method would be better in the sense of avoiding "global" variables which we all know are hard to keep control of. Thanks for the input Tom, I may yet do it that way.
Cheers Chris
 
Just thought I would put in my two cents.
It is a widely held opinion that session variables should be used with caution and explicit control. The reason being is that they are resource intensive and have performance issues.

Any way rather than goin into great detail here check this out.

By the way happy belated fathers day to any fathers out there. [peace]
 
Thanks, Zarcom, I knew they were far to easy to be fast. I think I'll use the querystring method after all...

;) Chris
 
It is right to believe that sessions aren't the best way to pass information from one aspx page to the other, but it's wrong to believe they are the worst way.
There has been a big improvement between the sessions used in normal ASP and the ones used in ASP.NET. There are other solutions, such as the new Cache object that can be "cookie free" for example.
But generally, in a small project, where you are passing a relatively small object, from one page to another, session variables can be the easiest way around. If you are afraid of the resources used, you can always set the Session variable equals to null once you have retrieved your data.
In most of the ADO.NET books you will find examples where entire DataSets are passed through a Session Variable.

Happy Programming!
 
One other thing to note:

If the data you're passing isn't sensitive, then the query string is a great idea. However, if you're passing something of a more sensitive nature (i.e. credit card numbers, user names and passwords, etc.), then the session variables are actually a better way to keep track of that sort of information (i.e. a user logs in, their credit number is stored in a session variable, and stays on the server; it never goes over the internet, where hackers could get a hold of it).

Just another thought.
:)

jack
 
And yet there's still another way to do this, too. ;-)

This is more something to think about when designing the flow of a site, but asp.net has what are called panels... and they're sort of like placeholders which you can set the visibility of...

You place page1 (or what would have been page 1) into panel1. Put page2's display logic into panel2.

Then show/hide as needed. Show/Hide having a whole new meaning in .net, though. Used to... things would still be written to the client and they would have 'style="visibility:hidden"', but now, the server sees that you wish to hide the panel, and just doesn't send it to the client at all.

Net effect to the user is like a whole other page, but you still have access to all the objects from postback.

:)
paul
penny1.gif
penny1.gif
 
now... don't we all love this .NET stuff??? many solutions, tricks and walkarounds!!!

I'm glad to be a .NET NUT lol
 
jfrost, thanks for mentioning the security issue, I indeed will be passing sensitive information between pages. I will have to look more deeply into this than I thought (I've never had to do that before... - groan).

Meanwhile I've been fighting with HTML tables.. groan again
Cheers Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top