Solved

How do I pass a Query String variable from one page to another?

Posted on 2009-04-09
10
712 Views
Last Modified: 2013-12-17
I have written a web site in C# .Net using Visual Studio 2008. I am using the asp.net 3.5 listview control bound to a linqdatasource on my page. I simply want to know how to pass a variable from my listview onto another page containing a listview. I thought the attached would work in my second listviews linqdatasource but I keep getting the error: "Object expected"? The variable I am trying to pass is TrustID. I am using the below link from within my first listviews itemtemplate to open a popup page and pass my variable into the second listview...

<a href="#" id="accountsLink" onclick="wopen('trustAccounts.aspx?trustid=<%#Eval "TrustID")%>', 'popup', 400, 250); return false;" >Pass Variable to ListView 2</a>
<asp:LinqDataSource 
                                            ID="LinqDataSourceAccounts" 
                                            runat="server" 
                                            ContextTypeName="TrustSystemMARTINSPALDINGDataContext"
                                            EnableDelete="True" 
                                            EnableInsert="True" 
                                            EnableUpdate="True"
                                            TableName="TrustAccounts" 
                                            onselecting="LinqDataSourceAccounts_Selecting" 
                                            Where="TrustID = @trustID">
                                            <WhereParameters>
                                                <asp:QueryStringParameter 
                                                    Type="Int32" 
                                                    DefaultValue="706" 
                                                    Name="TrustID" 
                                                    QueryStringField="TrustID" />
                                            </WhereParameters>
                                        </asp:LinqDataSource>

Open in new window

0
Comment
Question by:Shepwedd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 5

Expert Comment

by:burningmace
ID: 24106295
Use a session. When you create a session, the variables stored for that session (server side) are kept between pages. A few tutorials and infomation pages are below:

http://asp.net-tutorials.com/state/sessions/
http://www.beansoftware.com/ASP.NET-Tutorials/Managing-Sessions.aspx
http://msdn.microsoft.com/en-us/library/ms972429.aspx
http://quickstart.developerfusion.co.uk/QuickStart/webservices/doc/Intrinsics.aspx

You can also try googling for "ASP.NET Sessions" or "ASP.NET Session Tutorial".

Cheers,
Burningmace
0
 
LVL 10

Expert Comment

by:GeoffSutton
ID: 24106319
What happens if you check the TrustID value in the Page_Load (Request["TrustID"] or Request("TrustID") in VB).  Also, have you tried Where='<%=Request["TrustID"] %>' and get away from the Query Parameters?
Geoff
0
 
LVL 28

Expert Comment

by:sybe
ID: 24106549
Session is a bad idea. Sessions are meant for (as the name says) "sessions". Using a session will go wrong for example when a user has two windows open on your application.

<%=Request.Querystring("TrustID")%> should work
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:Shepwedd
ID: 24106809
sybe,

Where exactly would I place your code? Obviously inside the .aspx page but where? Instead of the <%#Eval "TrustID")%>?

Thanks.
0
 
LVL 28

Expert Comment

by:sybe
ID: 24106822
> Instead of the <%#Eval "TrustID")%>?

If that is where you need it, then yes, put it there.
0
 

Author Comment

by:Shepwedd
ID: 24106881
I've now changed LinqDataSource code of the listview receiving the variable to the attached but I still get the same error?
<asp:LinqDataSource 
                                            ID="LinqDataSourceAccounts" 
                                            runat="server" 
                                            ContextTypeName="TrustSystemMARTINSPALDINGDataContext"
                                            EnableDelete="True" 
                                            EnableInsert="True" 
                                            EnableUpdate="True"
                                            TableName="TrustAccounts" 
                                            onselecting="LinqDataSourceAccounts_Selecting" 
                                            Where='<%=Request.Querystring("TrustID")%>'>
                                        </asp:LinqDataSource>

Open in new window

0
 

Author Comment

by:Shepwedd
ID: 24106904
GeoffSutton,

How do I check the TrustID value in the Page_Load?

I've tried your code: Request["TrustID"] in my code behind page_load event but it errors?
0
 
LVL 10

Expert Comment

by:GeoffSutton
ID: 24107320
Sorry... Are you using C# or VB.NET?  With C# you would put a line something like "String tmp=Request.Querystring["TrustID"]" and in VB.NET use 'Dim tmp as String = Request.Querystring("TrustID")'.
Then put a break on that line then run the application.  Once the application breaks on that line you can mouse over the variables and find out their values.  This will ensure that the correct data is being passed and read.  Note:  You will have to hit F11 once for tmp to acquire the value.  If you are getting a value, then in your LINQDatasource, put the same thing (Where='<%=Request.Querystring("TrustID")%>' in VB.NET, Where='<%=Request.Querystring["TrustID"]%>' in C#).  If you are still getting the same error, then the TrustID is not the source of your problems.
Let me know how this works for you.
Geoff


0
 

Author Comment

by:Shepwedd
ID: 24136450
GeoffSutton,

I'm using C#. After using your code my tmp variable is returning null? From my first listview (lvTrustAccounts) I have a button within my itemTemplate which has an onclick event equal to:

Response.Redirect("trustAccounts.aspx?trustid=" + lvTrustAccounts.SelectedValue);

The select statement within this listviews linqdatasource returns the TrustID among other values so I'm not too sure why my page_load is returning null?


0
 

Accepted Solution

by:
Shepwedd earned 0 total points
ID: 24136766
This solution is as simple as:

<asp:HyperLink runat="server" id="hlNavigate" NavigateUrl='<%#  "~/trustAccounts.aspx?Id=" + Eval("TrustID") %>' Text="Accounts" />
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question