No...because sometimes the request.querystring("custo
Main Topics
Browse All TopicsHi All,
I have a very weird problem going on. Here is my code:
If Not IsPostBack Then
DoSessionStuffHere()
If Request.QueryString("Custo
Response.Write("<script> alert('In order to view Regular Contracts a Customer must be chosen first.')</script>")
'Response.Redirect("defaul
Server.Transfer("default.a
Else
.....blah
End If
End If
Private Sub DoSessionStuffHere()
If Request.QueryString("Custo
Session("MyCurrentCustomer
ElseIf Request.QueryString("Custo
Session.Item("MyCurrentCus
End If
End Sub
Problem: When I first go to the page the session variable is set correctly when my querystring=customer(somet
Thoughts?
Thanks,
Muligan
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Here is some debugging:
Private Sub DoSessionStuffHere()
If Request.QueryString("Custo
Response.Write("<script> alert('inside session') </script>")
Session("MyCurrentCustomer
Response.Write("<script> alert('" + Session.Item("MyCurrentCus
ElseIf Request.QueryString("Custo
'Session.Abandon()
'Session.Clear()
Response.Write("<script> alert('inside session 2') </script>")
Session.Item("MyCurrentCus
Response.Write("<script> alert('2:" + Session.Item("MyCurrentCus
End If
End Sub
If you look at the sub...you will notice I put in some alerts. On the second pass thru this page where I "should" be changing the session variable...I will see the "inside session 2" message... so I know it is making it to the right place and that the session should be resetting, but it just isn't happening.
Could this be a setting in IIS?
are you sure this is the only place where you are setting the session variable? If you want to retain the session varaible, there is no need for this statement
>>Session("MyCurrentCustom
try this code
If Request.QueryString("Custo
Session.Item("MyCurrentCus
End If
It's unclear to me how you are "coming back to the page". In your code, if you ever post-back with a different querystring, your code won't work because you are calling DoSessionStuffHere() only when IsPostBack is false.
Also, I'm a C# guy, but I can't help noticing that you're referring to Session("MyCurrentCustomer
In general, set a breakpoint at
Session.Item("MyCurrentCus
See what the rvalue [Request.QueryString("Cust
The lines
If Request.QueryString("Custo
Session("MyCurrentCustomer
seem to have absolutely no purpose and should be removed.
Regards,
-- Jon500
Good suggestion, Rejojohny.
If you want to test whether the Session is being set elsewhere, just change the URL while on the page to a different customer number and postback. If that works (you will need to call DoSessionStuffHere() on each postback, though), then Rejojohny is probably correct--that Session("Customer") is being modified elsewhere. But, even if it is, your forced call to DoSessionStuffHere() should reset it to the QueryString value that applies to the current postback.
-- Jon500
Are you also certain that your url is well-formed? I've seen programmers make mistakes with the querystring arguments on postbacks (for example, misspelling "customer", or forgetting a "&" delimiter). Just another thought... It's unclear to me what you're posting back FROM, so I thought I'd suggest this.
-- Jon500
I agree with you... I totally took out the session=session
Here is what I have now:
Private Sub DoSessionStuffHere()
If Request.QueryString("Custo
Session("MyCurrentCustomer
End If
End Sub 'DoSessionStuffHere
Problem is now... when the page is loaded... I get the error: Object reference not set to an instance of an object. And it points to the .Length > 0 line.
Thoughts?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DoSessionStuffHere()
If Request.QueryString("Custo
Response.Write("<script> alert('In order to view Regular Contracts a Customer must be chosen first.'); window.location = 'default.aspx' </script>")
'Response.Redirect("defaul
End If
If Not IsPostBack Then
DoSessionStuffHere()
If Request.QueryString("Custo
Response.Write("<script> alert('In order to view Regular Contracts a Customer must be chosen first.'); window.location = 'default.aspx' </script>")
'Response.Redirect("defaul
Else
..........blah
End If
End If
End Sub
Private Sub DoSessionStuffHere()
If Not Request.QueryString("Custo
Session("MyCurrentCustomer
End If
End Sub
Thougths?
Load home page
Click on John's contracts
First page load of contracts page: customer=john
Session mycurrentcustomer=john
Click on link to homepage
Click on Jim's contracts
Second page load of contracts page: customer=jim
Session mycurrentcustomer=jim
Click on link to homepage
Click on a link (that is basically like a back button) and session of mycurrentcustomer=john again... where did jim go?
I'm trying to put my application in simple terms to understand....but here is exactly what happens:
There are links along the left that let you navigate to parts of the application. If a user comes to the site and trys to click on contracts they will get that message shown above that tells them they must select a customer first...and it bounces them back to the homepage that has some parabolic searching (dropdown boxes filled from sql tables). Once the narrow down to a customer then are automatically directed to the contracts page. If the user then click on the homepage, then click on the contracts link (from left menu) they will see the customer they just searched on. But, if they click on the homepage (from left menu) and do the searching function again, and select a different customer, again they are bounced to the contracts page and the new customer information is displayed. BUT... if the user clicks on the homepage (from left menu) and then clicks on the contract link (from left) they should go back to the contracts page and see customer #2 that they searched for, but the user will see customer #1.
I hope that helps?
The links on the left menu contain to querystring information
while the datagrid on the homepage has a datagrid that has a column that looks like this:
<asp:HyperLinkColumn
HeaderText="Contract Review"
HeaderStyle-BackColor=#003
HeaderStyle-ForeColor="#ff
HeaderStyle-HorizontalAlig
DataNavigateUrlField="Cust
DataNavigateUrlFormatStrin
DataTextField="Customer"
DataTextFormatString="Revi
ItemStyle-HorizontalAlign=
Visible="true" />
"DataNavigateUrlFormatStri
appears to be a querystring URL.
May I ask a simple question? When you click that link from the Home page and you get Customer 1 instead of Customer 2, what exactly is the URL for the target page? In other words, are you seeing a QueryString with Customer=1???
Thanks,
-- Jon500
The URL is : Contracts.aspx?customer=AA
If I put in some alerts to show me the value of the session, it displays the proper customer (ie AAA11123)...even on the second pass. But as usual...if I click on the homepage link on the left menu...and then click on the contracts link on the left menu... I should see customer AAA11123's contracts... but I see the first customer that I searched on.
Well, this is the first mention of ViewState("myData"). I can't possibly help until I see more source code. That is why I was asking about how you are navigating to the contracts.aspx page from the home page. You said it was plain links, then I saw a querystring value embedded in the grid's hyperlink column, and now there is a new issue possibly with ViewState.
You still haven't answered my question about the customer ID in the querystring. If the querystring is wrong, then the page is not ever going to display the correct customer.
If you are realizing that the customerid is wrong in the querystring, you should be able to work backwards to determine how that URL is being requested and how the (wrong) querystring value is being assigned. Knowing this should allow you to solve the problem.
Keep me posted.
-- Jon500
I don't think the problem is the session variable at all. I think that is working now. So your going to get credit for your suggestions. My problem I think is in rebinding the datagrid. If I take my binding code that WAS inside of the
If Not IsPostBack Then
End IF
and put the code in just PageLoad... it almost works. After I follow the behavior described above...and get to the second customer. I click off the page can come back...the first customer grid info is displayed, but NOW if I hit the refresh but...the second customer then appears.
So... somehow I have to force the pageload code to work everytime...????
Hi,
I haven't see your "binding code", but you are correct that the page won't persist binding across pagebacks unless the ViewState is handling persistence for you, and that depends on your EnableViewState settings, etc.
I think the key, in all cases, is whether the correct ID is getting to your page by way of the QueryString value. You are correct that Session() is consistent (unless, as you already know, you overwrite it or the Session expires or--which is opening a whole new can--you are load-balanced to another web server that doesn't have access to session state).
It's unclear to me why the refresh is causing another customer to appear, but when you do a refresh, remember that IsPostBack will be true.
I'll be happy to continue to troubleshoot--I just need info from you!
Regards,
-- Jon500
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DoSessionStuffHere()
If Request.QueryString("Custo
Response.Write("<script> alert('In order to view Regular Contracts a Customer must be chosen first.'); window.location = 'default.aspx' </script>")
'Response.Redirect("defaul
End If
If Not Session("MyCurrentCustomer
Session("ConnProvStr") = "** my connect string **"
viewstate("sortexpression"
viewstate("sortdirection")
ReadExpenses()
GetCustomerData()
btnUpdateAll.Attributes.Ad
dgAnalysis.CurrentPageInde
ProductTypeFilterChange(se
Dim dsItemGrid As New DataSet
'Add a table to the dataset
dsItemGrid.Tables.Add("Ite
'Add columns to the dataset
dsItemGrid.Tables("Items")
dsItemGrid.Tables("Items")
dsItemGrid.Tables("Items")
dsItemGrid.Tables("Items")
ViewState("myData") = dsItemGrid
End If
lblSubmitted.Text = ""
End Sub
Private Sub DoSessionStuffHere()
If Not Request.QueryString("Custo
Response.Write("<script> alert('inside session') </script>")
Session("MyCurrentCustomer
Response.Write("<script> alert('" + Session.Item("MyCurrentCus
End If
End Sub 'DoSessionStuffHere
#End Region
Here is the customer bind:
Private Sub ReadExpenses()
Try
Dim strConnection As String = ConfigurationSettings.AppS
Dim strSQLcommand As String = "SELECT * FROM mytable WHERE Customer = '" + Session("MyCurrentCustomer
Dim objConnection As New SqlConnection(strConnectio
Dim objAdapter As New SqlDataAdapter(strSQLcomma
Dim dsContracts As New DataSet
objAdapter.Fill(dsContract
Dim dvContracts As New DataView(dsContracts.Table
dvContracts.Sort = viewstate("sortexpression"
dgContracts.DataSource = dvContracts
dgContracts.DataBind()
objConnection.Close()
Catch ex As Exception
End Try
End Sub
For those that may look at this someday...
I resolved this problem with something that isn't pretty:
Private Sub DoSessionStuffHere()
If Not Request.QueryString("Custo
Session("MyCurrentCustomer
Response.AppendHeader("Ref
End If
End Sub
I causes the page to refresh (yuck!), but it works.
I would rather see you add CACHE headers to your page to expire the content. I just thought about that. Caching can be established on the page and I am wondering if you are subclassing a page object that is adding a special CACHE header that is persisting your content. I really would get rid of this refresh idea.
-- Jon500
LOL... I just saw that:
Response.Cache.SetCacheabi
On this question: http://www.experts-exchang
Business Accounts
Answer for Membership
by: Jon500Posted on 2005-07-21 at 05:55:57ID: 14492985
Hi,
") = Session("MyCurrentCustomer "). ") = Request.QueryString("Custo mer") ?
The problem is Session("MyCurrentCustomer
Don't you want that to say: Session("MyCurrentCustomer
Regards,
-- Jon500