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

Alternative to Session Variable 2

Status
Not open for further replies.

LonnieJohnson

Programmer
Apr 16, 2001
2,628
0
0
US
I was wondering how I can pass a string from one page to another? I am using VS 2005.

I have a data grid on one page and I am opening another page with a grid and want to pass the sql of from the grid on page one to the gird on page two.

I was using a session varible but it seems unstable. The sql string value does not always see to carry over.

Thanks in advance.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Why do you need to pass a sql string? This seems strange no matter which method you use to pass it.

Why not have a stored procedure and each page that needs to use it just executes it?


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Thanks for responding.

On page one is sort of a query builder. The user gets to select which fields to show in the grid and what filter criteria they want. Once this is all done then the grid gets populated.

If they want to print, a button leads them to a second page opens with a grid that fills up the entire page so they may print the results.

Do you have another way to print this dynamically populated grid on page one? I didn't see a print grid property. I did not want to do a report because of not knowing the fields at runtime. It could be 1 field or 20 fields out of about 30.

So I pass the SQL string from grid one to the second page that does not have all the other stuff that I do not want printed.



ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
I'd still go with the SP route. Pass your parameters from one page to another and set the parameters when you call the SP.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
How do you send field names to the stored sproc at runtime? One run it may be...

SELECT ADDRESS, CITY, ZIP FROM CUSTOMERS WHERE AGE = 30

Then the next time they click the button it may be

SELECT COUNTY, STATE, ZIP FROM CUSTOMERS WHERE GENDER = 'MALE'

I can understand sending certain parms for the WHERE statement but how do I dynamically add fields?

Thanks again.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Ok, I think I may understand what you are talking about after I thought about it. I could send the field list to the stored proc as a string and it to the front of another string and exec the string within the sproc to return the rows.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
I still have the problem of the fields that were selected on page one to be passed to the stored sproc AFTER the opening of page two. I am still stumped.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
You can pass data from one page to another by passing them through the querystring, by posting them to the second page, using session or application variables or even by adding them to the Cache.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
What you are referring to is dynamic SQL. Since your column list will change possibly each time the page is run, then you have to build a string, and execute it in SQL Server. There are may posts referring to this (Dynamic SQL) in the sql forum:forum183
 
Thanks guys.

ca8msm,
I was already doing this with a session variable. That was my original problem, the session variable seems to get trashed sometimes. Depending upon how many times the user clicks the button to print the results.

I guess I can use the query string, but the SQL string would be kinda long. Does that matter?

jbenson001,
Thanks. I got that part down also, it's just getting my query grid to print page to receive that string.

Guys, am I going about this the right way?

1. I have a page with many text boxes and list boxes and such to determine criteria and fields to show in the results.

2. I want to print the results in the grid? How can I do this with the dynamic field list?

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
I guess I can use the query string, but the SQL string would be kinda long. Does that matter?
I didn't say to pass the SQL String through the querystring (and would strongly suggest not doing this). I said to pass the parameters from one page to another and then execute the SP on the second page.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Ok. Now there are a lot of parameters. Again this is a query builder program that allows the user to filter on about 15 fields and select any 1 or more of 30 fields. Wouldn't that be a long query string.

I really do apreciate your feedback. Thanks again.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
You can always create a class with a property for each parameter and set/get those values as needed.
 
That sounds intersting. Let me persue. I'll get back with you today.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Why do you need to redirect them to another page just to print? Can you make the first page printable? You can use css extensively for that part.

if the datagrid on page 1 already has the results, you can have a print event update a css class, or even set a hidden duplicate grid to be visible only when printed. No matter which print button the user clicks (yours or IE's) it should print properly.

if you think thats feasible, ill post some samples for you to start to build off of. Mostly it will be just setting the controls you dont want printed to a css class using media="print
 
Ok. That sounds workable. Can you send an example? Thanks.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
As Adam says, you just need to add another stylesheet and set the media attribute e.g.
Code:
<link rel="stylesheet" type="text/css" media="print" href="stylesheets/print.css" />
Add whatever CSS you need to style the page and the browser will take care of the rest (i.e it will use this stylesheet when the user chooses to print the page).


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Heres an example page that hopefully will guide you to the concept, and should be copy pasteable to see yourself.

TODO: Link your code-behind file, add your datagrid, ie.

To change this to have the results viewable AND printable, just change the screen style divResults from display: none; to display: block;

note: I ALWAYS use external stylesheets, but showing here just for simplistic approach.
Code:
<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head runat="server">
    <title>Printable Page</title>
<%-- Uncomment these for external stylesheet reference
    <link href="css/page.css" rel="stylesheet" type="text/css" media="screen" />
    <link href="css/print.css" rel="stylesheet" type="text/css" media="print" />
--%>
    <style media="screen" type="text/css">
        body
        {
            font-size: 11pt;
            font-family: Verdana;           
        }
        input
        {
            font-size: 9pt;
            font-family: Verdana;
        }
        #printCopy
        {
            display: none;
        }        
        #divSelections
        {
            border: solid 1px Gray;
            background-color: Green;
            color: White;
            padding: 10px;
        }
        #divResults
        {
            display: none;
        }
    </style>
    <style media="print" type="text/css">
        #printCopy
        {
            display: block;
            padding: 10px;
        }
        #divSelections
        {
            visibility: hidden;
            display: none;
        }
        #divResults
        {
            border: solid 1px Gray;
            display: block;
            padding: 10px;
        }        
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div id="divSelections">
            Please Make Your Selections Here
            <br />
            Choose This
            <br />
            <asp:Button ID="bntSubmit" runat="server" Text="Generate Grid" />
        </div>
        <div id="printCopy">
            &copy;Selection Maker v1.1
        </div>
        <div id="divResults">
            These are your results here! Thank you for making your selections!
        </div>
    </form>
</body>
</html>
 
Thanks a million. I am in a class right now. I will try it when I get in the office in the morning.

One other thing since I will be printing the original grid. This grid has the paging turned on and I only show ten lines at a time. Will the whole thing print?

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
It will only print the HTML that has been sent to the client. So, if you've only sent ten lines, that's all it can print.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top