UpdatePanel sessionstate

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sarabonn
    New Member
    • Nov 2008
    • 69

    UpdatePanel sessionstate

    Hallo everyone,

    I am using a VS 2005 and aspx.vb. i have a updatepanel with some textbox. So when the user the enters the data it filter's from sql table according to that and fill the gridview below the update panel. The gridview has a edit option.

    Now iam redirecting to another page as shown below in the selectedIndexch anged when the user click the edit button
    Code:
    Protected Sub gvListe_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvListe.SelectedIndexChanged
    
            
            Response.Redirect("AngebotDetails.aspx?Nummer=" & gvListe.SelectedValue.ToString)
    
        End Sub
    The problem now is after redirecting when i return to the page the session state is ended and all the filter value is the textbox is gone. so how can i resolve it by storing the sessionstate for my situation..

    It could be good it some code example.
    thank you..

    dinesh
    Last edited by Frinavale; Mar 26 '10, 07:33 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Session has not ended when you return to the page.
    Your ViewState has.

    ViewState contains the State information for all of the ASP.NET controls on the page.

    This means that if you have selected a value in a DropDownList, the selected value is stored in ViewState...lik ewise, if the user has entered text into a TextBox, the text is stored in ViewState.

    This is how ASP.NET controls remember what their state is between requests made to the server.

    Without ViewState the text the user entered into the TextBox and the item the user selected in the DropDownList would be lost when the user causes the browser to make a request to the server (postback)...un less you manually set the state of the controls every page request.

    Anyways, my point here is that you can store the index that the user selected into Session.

    Session is not bound to a particular page.
    Session exists on the server and provides you with a way to pass information between pages.

    So instead of having:
    Code:
    Response.Redirect("AngebotDetails.aspx?Nummer=" & gvListe.SelectedValue.ToString)
    You would have:
    Code:
    Session("nummer")=gvListe.SelectedValue.ToString
    Response.Redirect("AngebotDetails.aspx", True)
    Then in your AngebotDetails. aspx page you would retrieve the "nummer" like this:
    Code:
    Dim nummer As String = Session("nummer")

    When you come back to the original page you would do the same thing to retrieve "nummer" from Session and use that to re-set the DropDownList's selected value.

    -Frinny

    Comment

    • sarabonn
      New Member
      • Nov 2008
      • 69

      #3
      Hallo Frinny,

      Thank you for your reply. Actaully the problem not with the response redirect i think because the gvliste(gridvie w) nothing to store. I have a updatepanel which have 3 text box for the user to enter the value. When the user enter the value in the gridview it's filter according to the user input and displayed.

      Or is this could be the problem ?.. I have a Page_Init in that i looking for the Http.context.us er.identity.nam e and filling in like this
      Code:
      Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
             
              ' Erster Seitenaufruf
      
              If oSet.Benutzerstatus = "X" Then
                  Response.Redirect("Fehler.aspx")
              End If
              Dim strUser As String = Replace(HttpContext.Current.User.Identity.Name, oSet.NetBIOSDomaene, "").ToString
              tbErfasser.Text = strUser
              lbErfasser.Text = strUser
              tbVon.Text = Date.Today.AddDays(-120)
              lbVon.Text = Date.Today.AddDays(-120) & " 00:00:00"
              tbBis.Text = Date.Today
              lbBis.Text = Date.Today & " 23:59:59"
      
          End Sub
      and when the user give the input i do like this

      Code:
      Protected Sub FilterChanged(ByVal sender As Object, ByVal e As System.EventArgs)
      
              ' Filter wechseln
              lbKunde.Text = tbKunde.Text
              lbErfasser.Text = tbErfasser.Text
              lbVon.Text = tbVon.Text & " 00:00:00"
              lbBis.Text = tbBis.Text & " 23:59:59"
              lbGestellung.Text = tbGestellung.Text
              lbLadehafen.Text = tbLadehafen.Text
              tbEntladehafen.Text = tbEntladehafen.Text
              lbInfo.Text = tbInfo.Text
              lbAnsprechpartner.Text = tbAnsprechpartner.Text
      End Sub
      the gridview is assigned with the objectdatasourc e so depending upon the user input the data is filtered and displayed from the database. so when the user click edit in the gridview and come the page_init fill the data automatically, but the problem i am not filling all the field , so if this could be the problem then another text should remain the same but it's not..I don't know where the problem lies ..

      Dinesh.
      Last edited by Frinavale; Mar 30 '10, 01:27 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        It sounds like you want to pass the details of the row selected to the next page.
        Why don't you just create a class or structure to hold these details in Session so that you can access them on the next page.

        So when the user selects a row, grab all of the information from that row to populate the Object (of the custom class) with the data..then store this Object in Session so that you can access it on the next page....


        -Frinny

        Comment

        • sarabonn
          New Member
          • Nov 2008
          • 69

          #5
          Hallo Frinny,

          I don't want to take the value to the next page. The thing the value in the textbox should be stay as it is. the value's is just to sort the gridview and in the next page the data come's from the database. for the first time when the page is loading it check the default user and load the data of that user. After that when the user gives some other input to the textbox it filter according to that but the problem is the value changes after page postback.

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Then store the values into Session.
            When you come back to the the page, retrieve the values from session and re-populate the TextBoxes with it.

            You could also use cookies if you want to.....

            -Frinny

            Comment

            • sarabonn
              New Member
              • Nov 2008
              • 69

              #7
              Hallo Frinny,

              The problem is i shown above the populate the current user by give it on the page_Init so what ever i do i think when i visit the page it is populating the default value (bcos of the page_init).. Do you know some other way to check the page postback (i tired page.ispostback but no use bcecause of the page_init) or to populate the current user only when the user visit the page for the first time like that. do you any code example to use the cookies..

              Thank for vey much for your effort..

              dinesh.

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                Do this in your Page_Load event.

                The Page_Init event occurs after all of the Objects for the page have been loaded but before the ViewState for these Objects have been loaded.

                The Page_Init event occurs very very early in the ASP.NET Page Life Cycle.

                IsPostback is not loaded until after the Page_Init event has occurred because it is set/loaded/created when the ViewState is loaded for the page.

                So if you set the text properties of the controls in the Page_Init event...you can over write them in the Page_Load event (which comes after the ViewState for the controls on the has been loaded...after everything for the page has been loaded really).

                You would leave what you have in the Page Init event...and implement a method that handles the Page_Load event....which checks if there's anything in Session and if there is something sets the Text properties for the text boxes

                IsPostback is only true if some control On The Page caused the request to the server.
                This means that if you are coming from another page this is going to be FALSE!

                Because of this, just check if there's something set in Session...don't depend on IsPostback.

                :)

                -Frinny

                Comment

                • sarabonn
                  New Member
                  • Nov 2008
                  • 69

                  #9
                  Hallo Frinny ,

                  Thank you for your reply. Its working partly. what iam doing now is on the page_init i am populating the default user and filterchange (when the user enter the username in the textbox iam storing it in a session variable). I am using the session variable in the page_load by overwriting the textbox value it works but only one time. visit the other page and come back the session variable perfectly the pervious value in the textbox but after if i change to change the value in the textbox it is not working . To get a clear idea iam posting the code below..
                  Code:
                  Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
                         
                          ' Erster Seitenaufruf
                  
                          If oSet.Benutzerstatus = "X" Then
                              Response.Redirect("Fehler.aspx")
                          End If
                          Dim strUser As String = Replace(HttpContext.Current.User.Identity.Name, oSet.NetBIOSDomaene, "").ToString
                          tbErfasser.Text = strUser
                          lbErfasser.Text = strUser
                          tbVon.Text = Date.Today.AddDays(-120)
                          lbVon.Text = Date.Today.AddDays(-120) & " 00:00:00"
                          tbBis.Text = Date.Today
                          lbBis.Text = Date.Today & " 23:59:59"
                  
                      End Sub
                  storing it in session varaible when the user change the value in the textbox.
                  Code:
                  Protected Sub FilterChanged(ByVal sender As Object, ByVal e As System.EventArgs)
                  
                          ' Filter wechseln
                          lbKunde.Text = tbKunde.Text
                          lbErfasser.Text = tbErfasser.Text
                  
                          Session("nummer") = lbErfasser.Text [B]<--- Here [/B]
                  
                          lbVon.Text = tbVon.Text & " 00:00:00"
                          lbBis.Text = tbBis.Text & " 23:59:59"
                          lbGestellung.Text = tbGestellung.Text
                          lbLadehafen.Text = tbLadehafen.Text
                          tbEntladehafen.Text = tbEntladehafen.Text
                          lbInfo.Text = tbInfo.Text
                          lbAnsprechpartner.Text = tbAnsprechpartner.Text
                      End Sub
                  Pageload iam storing back the session value
                  Code:
                  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                          If (Session("nummer") = Nothing) Then
                  
                          Else
                              tbErfasser.Text = Session("nummer")
                              tbVon.Text = Date.Today.AddDays(-120)
                              lbVon.Text = Date.Today.AddDays(-120) & " 00:00:00"
                              tbBis.Text = Date.Today
                              lbBis.Text = Date.Today & " 23:59:59"
                  
                          End If
                  
                     End Sub
                  the second the session variable is not getting overwritted..

                  Thank you..

                  dinesh.
                  Last edited by Frinavale; Mar 30 '10, 03:36 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

                  Comment

                  • Frinavale
                    Recognized Expert Expert
                    • Oct 2006
                    • 9749

                    #10
                    Wow I don't know how your code works.

                    This wont work:
                    If Session("nummer ") = Nothing


                    If you want to check to see if something IS nothing you need to use the "is" or the "isnot" operators.

                    For example:
                    Code:
                    If Session("nummer") Is Nothing Then
                      ' do something
                    End If
                    Or:
                    Code:
                    If Session("nummer") IsNot Nothing Then
                      ' do something
                    End If
                    You aren't posting working code but I think you're still understanding what we're getting at.


                    I recommend that you store the value that the user entered in the TextBoxes into Session every time the page posts back.

                    You can do this in either the Page_Load event or the Page_PreRender event. You cannot do this in the Page_Init event because the Text entered into the TextBoxes has not been loaded from ViewState at this point in the life cycle.

                    -Frinny

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #11
                      Please do me a favor...
                      Whenever you post code could you please post it in code tags. It makes code easier to read and it gives us line numbers to refer to :)

                      Thanks!

                      -Frinny

                      Comment

                      • sarabonn
                        New Member
                        • Nov 2008
                        • 69

                        #12
                        Hallo Frinny,

                        Now I have added everything in the Page_prerender event and working fine..

                        Thank you for all your reply..

                        May be if some problem resist in this session in future i will reply in the thread :-)..

                        Dinesh.

                        Comment

                        • Frinavale
                          Recognized Expert Expert
                          • Oct 2006
                          • 9749

                          #13
                          :) I'm really glad you got this working :)

                          -Frinny

                          Comment

                          Working...