Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. can we store viewstate in masterpage?

can we store viewstate in masterpage?

Scheduled Pinned Locked Moved ASP.NET
question
27 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Suresh Pirsquare

    can we store viewstate in masterpage. so that when a user tries to open a new tab, the id is fetched from the viewstate.

    Everything Is Possible!

    A Offline
    A Offline
    Abhijit Jana
    wrote on last edited by
    #2

    Suresh Dayma wrote:

    can we store viewstate in masterpage.

    I didn't get your question. What do you mean by store view state in master page. I would suggest you to have a qucik look into Beginner's Guide To View State [^]article, and let me know if you have any more issue.

    Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

    S 1 Reply Last reply
    0
    • A Abhijit Jana

      Suresh Dayma wrote:

      can we store viewstate in masterpage.

      I didn't get your question. What do you mean by store view state in master page. I would suggest you to have a qucik look into Beginner's Guide To View State [^]article, and let me know if you have any more issue.

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

      S Offline
      S Offline
      Suresh Pirsquare
      wrote on last edited by
      #3

      Thanks for your reply. ok, just take an example this is what i want in masterpage, i have created a label called 'customer name'. and fetched the customer name from the database and assigned it to the label. when i navigate from one page to another then, I just want to retain the customer name across multiple pages without having to interact with the database. (Assume there is a single master page and multipe content pages.)

      Everything Is Possible!

      A 1 Reply Last reply
      0
      • S Suresh Pirsquare

        Thanks for your reply. ok, just take an example this is what i want in masterpage, i have created a label called 'customer name'. and fetched the customer name from the database and assigned it to the label. when i navigate from one page to another then, I just want to retain the customer name across multiple pages without having to interact with the database. (Assume there is a single master page and multipe content pages.)

        Everything Is Possible!

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #4

        Suresh Dayma wrote:

        when i navigate from one page to another then, I just want to retain the customer name across multiple pages without having to interact with the database.

        For that you need to use Session insted of ViewState. Fetch the data first time from DB and put it into session. Now you can access them any where from your site. Following code is used for storing a value to session Collapse

          //Storing UserName in Session
           Session\["CustomerName"\] = dbUserName;
        

        Now, let see how we can retrieve values from Session Collapse

        //Check weather session variable null or not
        if (Session["CustomerName"] != null)
        {
        //Retrieving UserName from Session
        lblWelcome.Text = "Welcome : " + Session["CustomerName"];
        }
        else
        {
        //Do Something else
        }

        Hope this will help you. If you want to know more about the session, please read this one : Exploring Session in ASP.Net[^]

        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

        S N 2 Replies Last reply
        0
        • A Abhijit Jana

          Suresh Dayma wrote:

          when i navigate from one page to another then, I just want to retain the customer name across multiple pages without having to interact with the database.

          For that you need to use Session insted of ViewState. Fetch the data first time from DB and put it into session. Now you can access them any where from your site. Following code is used for storing a value to session Collapse

            //Storing UserName in Session
             Session\["CustomerName"\] = dbUserName;
          

          Now, let see how we can retrieve values from Session Collapse

          //Check weather session variable null or not
          if (Session["CustomerName"] != null)
          {
          //Retrieving UserName from Session
          lblWelcome.Text = "Welcome : " + Session["CustomerName"];
          }
          else
          {
          //Do Something else
          }

          Hope this will help you. If you want to know more about the session, please read this one : Exploring Session in ASP.Net[^]

          Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

          S Offline
          S Offline
          Suresh Pirsquare
          wrote on last edited by
          #5

          Currently, i have used the sessions to store this. but when the user tries to open it in a new tab then this does not work. Example I have a gridview having multiple customers. if i open multiple customer details on multiple tabs then it will overwrite the customer details. so it does not make sense to store customer details in Session.

          Everything Is Possible!

          A A 2 Replies Last reply
          0
          • A Abhijit Jana

            Suresh Dayma wrote:

            when i navigate from one page to another then, I just want to retain the customer name across multiple pages without having to interact with the database.

            For that you need to use Session insted of ViewState. Fetch the data first time from DB and put it into session. Now you can access them any where from your site. Following code is used for storing a value to session Collapse

              //Storing UserName in Session
               Session\["CustomerName"\] = dbUserName;
            

            Now, let see how we can retrieve values from Session Collapse

            //Check weather session variable null or not
            if (Session["CustomerName"] != null)
            {
            //Retrieving UserName from Session
            lblWelcome.Text = "Welcome : " + Session["CustomerName"];
            }
            else
            {
            //Do Something else
            }

            Hope this will help you. If you want to know more about the session, please read this one : Exploring Session in ASP.Net[^]

            Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #6

            Abhijit Jana wrote:

            lblWelcome.Text = "Welcome : " + Session["CustomerName"];

            This won't compile. Adding a string and object is invalid. You need ToString().

            lblWelcome.Text = "Welcome : " + Session["CustomerName"].ToString();

            :)

            Best wishes, Navaneeth

            A 1 Reply Last reply
            0
            • N N a v a n e e t h

              Abhijit Jana wrote:

              lblWelcome.Text = "Welcome : " + Session["CustomerName"];

              This won't compile. Adding a string and object is invalid. You need ToString().

              lblWelcome.Text = "Welcome : " + Session["CustomerName"].ToString();

              :)

              Best wishes, Navaneeth

              A Offline
              A Offline
              Abhijit Jana
              wrote on last edited by
              #7

              My Bad. Thanks for correcting me !!:thumbsup:

              Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

              S 1 Reply Last reply
              0
              • S Suresh Pirsquare

                Currently, i have used the sessions to store this. but when the user tries to open it in a new tab then this does not work. Example I have a gridview having multiple customers. if i open multiple customer details on multiple tabs then it will overwrite the customer details. so it does not make sense to store customer details in Session.

                Everything Is Possible!

                A Offline
                A Offline
                Abhijit Jana
                wrote on last edited by
                #8

                Suresh Dayma wrote:

                but when the user tries to open it in a new tab then this does not work.

                Are you talking about browser new Tab ?

                Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                S 2 Replies Last reply
                0
                • S Suresh Pirsquare

                  Currently, i have used the sessions to store this. but when the user tries to open it in a new tab then this does not work. Example I have a gridview having multiple customers. if i open multiple customer details on multiple tabs then it will overwrite the customer details. so it does not make sense to store customer details in Session.

                  Everything Is Possible!

                  A Offline
                  A Offline
                  Abhishek Sur
                  wrote on last edited by
                  #9

                  I think you need to use Database. Once it is modified, just store it into database and from any other tab / in any other browser in the world, it will be shown updated. No need for ViewState / Session etc. ;) If this is your temporary storage, u might use temporary database tables as well. :rose:

                  Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                  My Latest Articles-->** Simplify Code Using NDepend
                  Basics of Bing Search API using .NET
                  Microsoft Bing MAP using Javascript

                  S 1 Reply Last reply
                  0
                  • A Abhijit Jana

                    My Bad. Thanks for correcting me !!:thumbsup:

                    Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                    S Offline
                    S Offline
                    Suresh Pirsquare
                    wrote on last edited by
                    #10

                    is there any workaround for this issue?

                    Everything Is Possible!

                    A 1 Reply Last reply
                    0
                    • A Abhijit Jana

                      Suresh Dayma wrote:

                      but when the user tries to open it in a new tab then this does not work.

                      Are you talking about browser new Tab ?

                      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                      S Offline
                      S Offline
                      Suresh Pirsquare
                      wrote on last edited by
                      #11

                      yes, you are correct

                      Everything Is Possible!

                      1 Reply Last reply
                      0
                      • S Suresh Pirsquare

                        is there any workaround for this issue?

                        Everything Is Possible!

                        A Offline
                        A Offline
                        Abhishek Sur
                        wrote on last edited by
                        #12

                        I have already suggested one workaround I guess... See, Viewstate is stored in page (So Rejected) Session is stored in server but for a single session (Rejected as IE opens a new session for each tab) Application is User Independent. Cookie ... Domain specific. Its possible to use this, But I dont like it as client can easily clear that. Also if is browser specific. Say one person opens the same site once in IE another in Mozilla.. Cookies will be different, (Hence Rejected) So there is only one option. Just change it globally, so that anywhere the change is reflected. Hope you got it. cheers. :rose:

                        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                        My Latest Articles-->** Simplify Code Using NDepend
                        Basics of Bing Search API using .NET
                        Microsoft Bing MAP using Javascript

                        S 1 Reply Last reply
                        0
                        • A Abhishek Sur

                          I have already suggested one workaround I guess... See, Viewstate is stored in page (So Rejected) Session is stored in server but for a single session (Rejected as IE opens a new session for each tab) Application is User Independent. Cookie ... Domain specific. Its possible to use this, But I dont like it as client can easily clear that. Also if is browser specific. Say one person opens the same site once in IE another in Mozilla.. Cookies will be different, (Hence Rejected) So there is only one option. Just change it globally, so that anywhere the change is reflected. Hope you got it. cheers. :rose:

                          Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                          My Latest Articles-->** Simplify Code Using NDepend
                          Basics of Bing Search API using .NET
                          Microsoft Bing MAP using Javascript

                          S Offline
                          S Offline
                          Suresh Pirsquare
                          wrote on last edited by
                          #13

                          I really appreciate your help. but still i have to make changes in all the content pages(i.e. globally) right. Isn't there way by which i have to make changes in the masterpage itself?

                          Everything Is Possible!

                          A 2 Replies Last reply
                          0
                          • S Suresh Pirsquare

                            I really appreciate your help. but still i have to make changes in all the content pages(i.e. globally) right. Isn't there way by which i have to make changes in the masterpage itself?

                            Everything Is Possible!

                            A Offline
                            A Offline
                            Abhishek Sur
                            wrote on last edited by
                            #14

                            You are most welcome.. Dont forget to click "good answer" if it actually helped you and also to mark that as answer for future reference. ;)

                            Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                            My Latest Articles-->** Simplify Code Using NDepend
                            Basics of Bing Search API using .NET
                            Microsoft Bing MAP using Javascript

                            1 Reply Last reply
                            0
                            • A Abhishek Sur

                              I think you need to use Database. Once it is modified, just store it into database and from any other tab / in any other browser in the world, it will be shown updated. No need for ViewState / Session etc. ;) If this is your temporary storage, u might use temporary database tables as well. :rose:

                              Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                              My Latest Articles-->** Simplify Code Using NDepend
                              Basics of Bing Search API using .NET
                              Microsoft Bing MAP using Javascript

                              S Offline
                              S Offline
                              Suresh Pirsquare
                              wrote on last edited by
                              #15

                              I dont think this is the solution.

                              Everything Is Possible!

                              A 1 Reply Last reply
                              0
                              • A Abhijit Jana

                                Suresh Dayma wrote:

                                but when the user tries to open it in a new tab then this does not work.

                                Are you talking about browser new Tab ?

                                Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                                S Offline
                                S Offline
                                Suresh Pirsquare
                                wrote on last edited by
                                #16

                                Hi abhijit, is there any work around for this issue?

                                Everything Is Possible!

                                1 Reply Last reply
                                0
                                • S Suresh Pirsquare

                                  I dont think this is the solution.

                                  Everything Is Possible!

                                  A Offline
                                  A Offline
                                  Abhishek Sur
                                  wrote on last edited by
                                  #17

                                  Then please let me clear this. If you open a new browser tab, it doesnt allow you to access any data from other tab because of security issues. Mozilla retains its session data for every tab. So in case of mozilla, it do work in multiple tabs. But in IE it doesnt. One thing that you might use is Cookie. If you call a server for same domain, you can use it to send data. Say you call www.xyz.com it can create cookie data in browser based on the address. So that after a certain while or at the same instant if a new browser is opened and same address is navigated, you will find the data from cookie easily. Say you write like this : Response.Cookies["txtCookie"].Value = this.txtcookie.Text; Response.Cookies["txtCookie"].Expires = DateTime.Now.AddDays(1); Now from another browser instance if you call string txtCookie = Request.Cookies["txtCookie"].Value; it will give you appropriate data. By this way you can send data to different browser instances. :cool:

                                  Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                                  My Latest Articles-->** Simplify Code Using NDepend
                                  Basics of Bing Search API using .NET
                                  Microsoft Bing MAP using Javascript

                                  1 Reply Last reply
                                  0
                                  • S Suresh Pirsquare

                                    I really appreciate your help. but still i have to make changes in all the content pages(i.e. globally) right. Isn't there way by which i have to make changes in the masterpage itself?

                                    Everything Is Possible!

                                    A Offline
                                    A Offline
                                    Abhishek Sur
                                    wrote on last edited by
                                    #18

                                    No you can do that in Masterpage as well. Just write your code in masterpage page_load and it will work perfectly. :)

                                    Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                                    My Latest Articles-->** Simplify Code Using NDepend
                                    Basics of Bing Search API using .NET
                                    Microsoft Bing MAP using Javascript

                                    S 1 Reply Last reply
                                    0
                                    • A Abhishek Sur

                                      No you can do that in Masterpage as well. Just write your code in masterpage page_load and it will work perfectly. :)

                                      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                                      My Latest Articles-->** Simplify Code Using NDepend
                                      Basics of Bing Search API using .NET
                                      Microsoft Bing MAP using Javascript

                                      S Offline
                                      S Offline
                                      Suresh Pirsquare
                                      wrote on last edited by
                                      #19

                                      No dear, it does not work.

                                      Everything Is Possible!

                                      A 1 Reply Last reply
                                      0
                                      • S Suresh Pirsquare

                                        No dear, it does not work.

                                        Everything Is Possible!

                                        A Offline
                                        A Offline
                                        Abhishek Sur
                                        wrote on last edited by
                                        #20

                                        Tell me what you did so far. Just do like this : write Response.Cookies["txtCookie"].Value = myid; Response.Cookies["txtCookie"].Expires = DateTime.Now.AddDays(1); inside your masterpage, and it will be accessible to any page that inherits masterpage (also normal pages) I have done this a lot of times, and it worked perfectly... To request the cookie use Request.Cookies["txtCookie"] :-D

                                        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                                        My Latest Articles-->** Simplify Code Using NDepend
                                        Basics of Bing Search API using .NET
                                        Microsoft Bing MAP using Javascript

                                        S 1 Reply Last reply
                                        0
                                        • A Abhishek Sur

                                          Tell me what you did so far. Just do like this : write Response.Cookies["txtCookie"].Value = myid; Response.Cookies["txtCookie"].Expires = DateTime.Now.AddDays(1); inside your masterpage, and it will be accessible to any page that inherits masterpage (also normal pages) I have done this a lot of times, and it worked perfectly... To request the cookie use Request.Cookies["txtCookie"] :-D

                                          Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                                          My Latest Articles-->** Simplify Code Using NDepend
                                          Basics of Bing Search API using .NET
                                          Microsoft Bing MAP using Javascript

                                          S Offline
                                          S Offline
                                          Suresh Pirsquare
                                          wrote on last edited by
                                          #21

                                          but my id keeps on changing depending on the no. of tabs opened(Firefox). And Each tab has to maintain different ids(customerId for instance). Example I have a gridview having multiple customers. if i open multiple customer details on multiple tabs then there should be different customerid assigned to different pages. In case if i use cookie then it will store a single customerid and when the page makes a request then this id will be assigned to all the pages. I dont want to do like this. I dont think, this is a solution(i.e. Cookie)

                                          Everything Is Possible!

                                          A 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups