Question

Session Variable not changing

Asked by: muligan

Hi All,

I have a very weird problem going on.  Here is my code:

If Not IsPostBack Then

            DoSessionStuffHere()

            If Request.QueryString("Customer") Is Nothing AndAlso Session("MyCurrentCustomer") Is Nothing Then
                Response.Write("<script> alert('In order to view Regular Contracts a Customer must be chosen first.')</script>")
                'Response.Redirect("default.aspx")
                Server.Transfer("default.aspx")
            Else
            .....blah
            End If

End If

Private Sub DoSessionStuffHere()

        If Request.QueryString("Customer") = "" Then
            Session("MyCurrentCustomer") = Session("MyCurrentCustomer")
        ElseIf Request.QueryString("Customer") <> "" Then
            Session.Item("MyCurrentCustomer") = Request.QueryString("Customer").ToString
        End If

    End Sub

Problem:  When I first go to the page the session variable is set correctly when my querystring=customer(something), Then if I click around my application can come back to the page, the session is still ok.  But...If I chose a different customer and go back to the page so the querystring=customer(something_different) ... it should reset my session variable to the new customer.  But it does not do this.  Seems pretty straight forward..but I can't get it to work...

Thoughts?

Thanks,

Muligan

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-07-21 at 05:47:44ID21499464
Tags

problem

,

session

,

variable

Topic

Programming for ASP.NET

Participating Experts
2
Points
500
Comments
58

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. isPostBack???
    Hai, Is there any function similar to the isPostBack of ASP.Net in JSP? Vikram.V
  2. Modify QueryString
    Hi, is there a way to programmatically modify values passed to a page via the QueryString without redirecting that page. for example, change: http://www.domain.com/page.aspx?reset=1 to: http://www.domain.com/page.aspx?reset=0 i need to do this within the code behind fi...
  3. Ispostback equivalent in Coldfusion.
    How can I check on a coldfusion page is ther was a postback. Like you have in asp IsPostback. Do we have something similar in coldfusion? I have a search form on coldfusion page and if someone comes to it for the first time I want to clear all session variables but if there ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

by: Jon500Posted on 2005-07-21 at 05:55:57ID: 14492985

Hi,

The problem is Session("MyCurrentCustomer") = Session("MyCurrentCustomer").
Don't you want that to say: Session("MyCurrentCustomer") = Request.QueryString("Customer") ?

Regards,
-- Jon500

 

by: muliganPosted on 2005-07-21 at 06:05:06ID: 14493030

No...because sometimes the request.querystring("customer") will be nothing, and at that point, I don't want to "empty out" the session variable.  I only want to reset the variable to something different if request.querystring("customer") is found or defined.

 

by: Jon500Posted on 2005-07-21 at 06:07:28ID: 14493046

Er, doesn't your line:
   If Request.QueryString("Customer") = "" Then
take care of that?

Think about it. What purpose does x = x serve? That's what your original code is doing.

-- Jon500

 

by: Jon500Posted on 2005-07-21 at 06:08:22ID: 14493054

Sorry--I misread something... Give me a sec...

 

by: muliganPosted on 2005-07-21 at 06:08:45ID: 14493056

Here is some debugging:

Private Sub DoSessionStuffHere()

        If Request.QueryString("Customer") = "" Then
            Response.Write("<script> alert('inside session') </script>")
            Session("MyCurrentCustomer") = Session("MyCurrentCustomer")
            Response.Write("<script> alert('" + Session.Item("MyCurrentCustomer") + "') </script>")

        ElseIf Request.QueryString("Customer") <> "" Then
            'Session.Abandon()
            'Session.Clear()
            Response.Write("<script> alert('inside session 2') </script>")
            Session.Item("MyCurrentCustomer") = Request.QueryString("Customer").ToString
            Response.Write("<script> alert('2:" + Session.Item("MyCurrentCustomer") + "') </script>")
        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?

 

by: RejojohnyPosted on 2005-07-21 at 06:09:08ID: 14493059

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("MyCurrentCustomer") = Session("MyCurrentCustomer")
try this code
        If Request.QueryString("Customer").Length > 0 Then
            Session.Item("MyCurrentCustomer") = Request.QueryString("Customer").ToString
        End If

 

by: muliganPosted on 2005-07-21 at 06:13:42ID: 14493087

Just to try... I commented out:

'Session("MyCurrentCustomer") = Session("MyCurrentCustomer")

And I get the same result

 

by: Jon500Posted on 2005-07-21 at 06:14:42ID: 14493095

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") when you read the value and Session.Item("MyCurrentCustomer") when you write it. Maybe you are required to do that in VB, but I'm not so sure and I thought I'd point it out.

In general, set a breakpoint at
   Session.Item("MyCurrentCustomer") = Request.QueryString("Customer").ToString

See what the rvalue [Request.QueryString("Customer").ToString] is when you think you should be getting a new Customer.

The lines
        If Request.QueryString("Customer") = "" Then
            Session("MyCurrentCustomer") = Session("MyCurrentCustomer")
seem to have absolutely no purpose and should be removed.

Regards,
-- Jon500

 

by: muliganPosted on 2005-07-21 at 06:17:55ID: 14493119

Yes... I did do a search on my entire project...and mycurrentcustomer session is not being set any other place.

 

by: Jon500Posted on 2005-07-21 at 06:17:58ID: 14493120

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

 

by: Jon500Posted on 2005-07-21 at 06:19:56ID: 14493137

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

 

by: muliganPosted on 2005-07-21 at 06:21:30ID: 14493144

I agree with you... I totally took out the session=session

Here is what I have now:

Private Sub DoSessionStuffHere()

        If Request.QueryString("Customer").Length > 0 Then
            Session("MyCurrentCustomer") = Request.QueryString("Customer")
        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?

 

by: Jon500Posted on 2005-07-21 at 06:24:17ID: 14493167

Try testing for Request.QueryString("Customer") = "". But using the .Length property, you're making an assumption that it the QueryString("Customer") can be resolved to an object.

Does that fix it?

-- Jon500

 

by: Jon500Posted on 2005-07-21 at 06:25:56ID: 14493189

Sorry--I meant "By using the .Length property..."

 

by: muliganPosted on 2005-07-21 at 06:29:31ID: 14493219

When I try to use:

Private Sub DoSessionStuffHere()

        If Not Request.QueryString("Customer").Length = "" Then
            Session("MyCurrentCustomer") = Request.QueryString("Customer")
        End If

    End Sub

I get the error: Input string was not in a correct format.

 

by: muliganPosted on 2005-07-21 at 06:29:43ID: 14493221

here is my code now:

 

by: muliganPosted on 2005-07-21 at 06:31:24ID: 14493235

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        DoSessionStuffHere()

        If Request.QueryString("Customer") Is Nothing AndAlso Session("MyCurrentCustomer") Is Nothing Then
            Response.Write("<script> alert('In order to view Regular Contracts a Customer must be chosen first.'); window.location = 'default.aspx' </script>")
            'Response.Redirect("default.aspx")
        End If

        If Not IsPostBack Then

            DoSessionStuffHere()

            If Request.QueryString("Customer") Is Nothing AndAlso Session("MyCurrentCustomer") Is Nothing Then
                Response.Write("<script> alert('In order to view Regular Contracts a Customer must be chosen first.'); window.location = 'default.aspx' </script>")
                'Response.Redirect("default.aspx")

            Else
            ..........blah
            End If
        End If

End Sub

Private Sub DoSessionStuffHere()

        If Not Request.QueryString("Customer") = "" Then
            Session("MyCurrentCustomer") = Request.QueryString("Customer")
        End If

    End Sub

Thougths?  

 

by: muliganPosted on 2005-07-21 at 06:32:36ID: 14493237

here is the page behavior:

 

by: Jon500Posted on 2005-07-21 at 06:34:23ID: 14493250

One thing:
You're now making a call to DoSessionStuffHere() every postback AND ALSO when IsPostBack is false. You only need to do the first DoSessionStuffHere() call in your Page_Load.

-- Jon500

 

by: muliganPosted on 2005-07-21 at 06:38:39ID: 14493278

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?

 

by: muliganPosted on 2005-07-21 at 06:40:06ID: 14493284

ok..took it out of the ispostback

 

by: Jon500Posted on 2005-07-21 at 06:42:52ID: 14493305

Wait! Please tell more about "Click on a link (that is basically like a back button)..."
What does the URL of the page look like when you click that?
And what exactly is this "basically like a back button" link doing? Is it a LinkButton control, or something else?

-- Jon500

 

by: muliganPosted on 2005-07-21 at 06:43:07ID: 14493307

still the same problem

 

by: muliganPosted on 2005-07-21 at 06:43:45ID: 14493313

I cleared my application pool as a "reach" for something to do...and it make a different

 

by: muliganPosted on 2005-07-21 at 06:44:05ID: 14493314

excuse me... did not make a difference

 

by: muliganPosted on 2005-07-21 at 06:51:15ID: 14493374

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?

 

by: Jon500Posted on 2005-07-21 at 06:54:20ID: 14493395

I think it helps. Then I would like to ask: What is the code-behind for the Contract Link on the Home page?

-- Jon500

 

by: muliganPosted on 2005-07-21 at 06:59:30ID: 14493422

That shouldn't matter...as there is no session variable information set or changed there.

 

by: muliganPosted on 2005-07-21 at 07:00:37ID: 14493429

just a datagrid...with some <asp:hyperlinkcolumns />

 

by: Jon500Posted on 2005-07-21 at 07:03:47ID: 14493452

Well, it could matter if the URL was being constructed there to include a Customer value. Is it? If not, does it just redirect to your target page with no QueryString information?

-- Jon500

 

by: muliganPosted on 2005-07-21 at 07:07:21ID: 14493477

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=#003366
            HeaderStyle-ForeColor="#ffffff"
            HeaderStyle-HorizontalAlign="center"
            DataNavigateUrlField="Customer"
            DataNavigateUrlFormatString="Contracts.aspx?customer={0}"
            DataTextField="Customer"
            DataTextFormatString="Review"
            ItemStyle-HorizontalAlign="center"
            Visible="true" />

 

by: muliganPosted on 2005-07-21 at 07:11:08ID: 14493508

excuse me... The links on the left menu contain NO querystring information

 

by: Jon500Posted on 2005-07-21 at 07:26:49ID: 14493621

"DataNavigateUrlFormatString="Contracts.aspx?customer={0}"
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

 

by: muliganPosted on 2005-07-21 at 07:35:21ID: 14493681

The URL is : Contracts.aspx?customer=AAA11123

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.

 

by: muliganPosted on 2005-07-21 at 07:36:42ID: 14493699

I tried putting in a session.abandon in my DoSessionStuffHere sub... but that seemed to screw everything up

 

by: Jon500Posted on 2005-07-21 at 07:41:02ID: 14493743

I'm trying to understand.
Contracts.aspx?customer=AAA11123

is the URL for the Second customer?
And you're saying that when you redirect to your page with this URL
Contracts.aspx?customer=AAA11123

the contracts.aspx page is displaying information for a customer other than AAA11123?

Thanks,
-- Jon500

 

by: muliganPosted on 2005-07-21 at 07:44:54ID: 14493769

I think I found the problem... the session is holding, but my

ViewState("myData") = dsItemGrid

is not changing... so when the contracts.aspx page is displaying it doesn't know to rebind with the new customer information?

 

by: Jon500Posted on 2005-07-21 at 07:53:46ID: 14493826

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

 

by: muliganPosted on 2005-07-21 at 08:00:53ID: 14493866

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...????

 

by: muliganPosted on 2005-07-21 at 08:04:51ID: 14493905

Do you think I need to put my datagrid binding code in the regular pageload or ispostback or not ispostback?

 

by: muliganPosted on 2005-07-21 at 08:05:42ID: 14493908

or maybe in two of the three?

 

by: Jon500Posted on 2005-07-21 at 08:07:21ID: 14493919

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

 

by: muliganPosted on 2005-07-21 at 08:14:17ID: 14493968

   Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        DoSessionStuffHere()

        If Request.QueryString("Customer") Is Nothing AndAlso Session("MyCurrentCustomer") Is Nothing Then
            Response.Write("<script> alert('In order to view Regular Contracts a Customer must be chosen first.'); window.location = 'default.aspx' </script>")
            'Response.Redirect("default.aspx")
        End If

        If Not Session("MyCurrentCustomer") = "" Then

            Session("ConnProvStr") = "** my connect string **"

            viewstate("sortexpression") = "CUSNAM"
            viewstate("sortdirection") = " ASC"

            ReadExpenses()
            GetCustomerData()

            btnUpdateAll.Attributes.Add("onClick", "javascript:return confirm('Are you sure you want to make these changes?')")

            dgAnalysis.CurrentPageIndex = 0

            ProductTypeFilterChange(sender, e)

            Dim dsItemGrid As New DataSet

            'Add a table to the dataset
            dsItemGrid.Tables.Add("Items")

            'Add columns to the dataset
            dsItemGrid.Tables("Items").Columns.Add("CUSNUM")
            dsItemGrid.Tables("Items").Columns.Add("NAME")
            dsItemGrid.Tables("Items").Columns.Add("ADD")
            dsItemGrid.Tables("Items").Columns.Add("MASPRICE")

            ViewState("myData") = dsItemGrid

        End If

        lblSubmitted.Text = ""

    End Sub

    Private Sub DoSessionStuffHere()

        If Not Request.QueryString("Customer") = "" Then
            Response.Write("<script> alert('inside session') </script>")
            Session("MyCurrentCustomer") = Request.QueryString("Customer")
            Response.Write("<script> alert('" + Session.Item("MyCurrentCustomer") + "') </script>")
        End If

    End Sub 'DoSessionStuffHere

#End Region

 

by: muliganPosted on 2005-07-21 at 08:29:41ID: 14494098

Simple question:

Is this: If Not IsPostBack Or IsPostBack Then

the same as just putting code in Page_Load?

 

by: Jon500Posted on 2005-07-21 at 08:36:56ID: 14494144

I still can't tell from the code above HOW you are getting the customer data. I assume it's in your GetCustomerData() function, but I can't see into that.

Why are you store grid data in ViewState("mydata")? Do you use ViewState("mydata") anywhere???

-- Jon500

 

by: muliganPosted on 2005-07-21 at 08:42:12ID: 14494179

Here is the customer bind:

Private Sub ReadExpenses()

        Try

            Dim strConnection As String = ConfigurationSettings.AppSettings("my conn string")

            Dim strSQLcommand As String = "SELECT * FROM mytable WHERE Customer = '" + Session("MyCurrentCustomer") + "'"

            Dim objConnection As New SqlConnection(strConnection)
            Dim objAdapter As New SqlDataAdapter(strSQLcommand, objConnection)
            Dim dsContracts As New DataSet

            objAdapter.Fill(dsContracts, "dtContracts")

            Dim dvContracts As New DataView(dsContracts.Tables("dtContracts"))
            dvContracts.Sort = viewstate("sortexpression") & viewstate("sortdirection")

            dgContracts.DataSource = dvContracts
            dgContracts.DataBind()

            objConnection.Close()

        Catch ex As Exception

        End Try

    End Sub

 

by: muliganPosted on 2005-07-21 at 08:51:35ID: 14494249

Yes, I use view state.. because I have a nested datagrid

 

by: muliganPosted on 2005-07-21 at 08:54:05ID: 14494269

I know its probably not the right answer.. but what if I was to put in some code to do an auto refresh in my page_load?

 

by: Jon500Posted on 2005-07-21 at 09:25:04ID: 14494459

You're right--auto refresh is a terrible approach.

You need to focus on the URL and ensure it's correct.

-- Jon500

 

by: muliganPosted on 2005-07-21 at 09:27:56ID: 14494473

I went thru the entire URL process and it is correct.

 

by: muliganPosted on 2005-07-21 at 11:17:06ID: 14495674

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("Customer") = "" Then
            Session("MyCurrentCustomer") = Request.QueryString("Customer")
            Response.AppendHeader("Refresh", "0; URL=http://micdev/application/SpecialPricing/RegularContracts.aspx")
        End If

    End Sub

I causes the page to refresh (yuck!), but it works.

 

by: muliganPosted on 2005-07-21 at 11:19:44ID: 14495706

Jon500...thanks for your help!

 

by: Jon500Posted on 2005-07-21 at 11:21:15ID: 14495728

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

 

by: muliganPosted on 2005-07-21 at 11:24:14ID: 14495762

LOL... I just saw that:

Response.Cache.SetCacheability(HttpCacheability.NoCache)

On this question: http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20995101.html?query=automatically+refresh+.net&clearTAFilter=true

 

by: muliganPosted on 2005-07-21 at 11:24:29ID: 14495768

That works perfectly!

 

by: Jon500Posted on 2005-07-21 at 11:27:23ID: 14495801

Great! So you should be pretty happy right now. :)

Whew! (As I wipe sweat from my forehead...)

Regards,
-- Jon500

 

by: muliganPosted on 2005-07-21 at 11:30:35ID: 14495845

Yeah...very happy...gheez... didn't think this would be such an issue.  Thanks for the help thou!

 

by: Jon500Posted on 2005-07-21 at 11:45:01ID: 14496011

That make TWO OF US! :]

Enjoy!
-- Jon500

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...