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. Changing the location of _viewState in the aspx page

Changing the location of _viewState in the aspx page

Scheduled Pinned Locked Moved ASP.NET
question
8 Posts 3 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.
  • J Offline
    J Offline
    JohnyCoder
    wrote on last edited by
    #1

    Hi: Hello everyOne. How can i change the default location(usually the first control in the form when view the page source) of _viewState hidden form field in the aspx page. For eg when some one view the source of my aspx page, the _viewstate field should not show up at the top of the page (in the page source. it looks junk). I hope u are uderstanding what i m trying to achieve.Its all for SEO perposes. Any Ideas? Thanks Aamir

    S 1 Reply Last reply
    0
    • J JohnyCoder

      Hi: Hello everyOne. How can i change the default location(usually the first control in the form when view the page source) of _viewState hidden form field in the aspx page. For eg when some one view the source of my aspx page, the _viewstate field should not show up at the top of the page (in the page source. it looks junk). I hope u are uderstanding what i m trying to achieve.Its all for SEO perposes. Any Ideas? Thanks Aamir

      S Offline
      S Offline
      sam L 0
      wrote on last edited by
      #2

      You can either turn the view state off for a particular control, or even for the entire page...however that's not adviceable as you won't be able to keep the state of your other controls around across post back. Now if you turn it off for the page, then when you go do source -> view, you are not going to see the view state field there. I am not sure why would you be concerned with where the view state shows up in your source...I mean if you are concerned with the date that you are storing in there being displayed, well its base 64 encoded so a reader can't just read it. However it's not encrypted or anything and there are base 64 decoders out there that can simply decode it for you. I hope this helps. Sam

      F J 2 Replies Last reply
      0
      • S sam L 0

        You can either turn the view state off for a particular control, or even for the entire page...however that's not adviceable as you won't be able to keep the state of your other controls around across post back. Now if you turn it off for the page, then when you go do source -> view, you are not going to see the view state field there. I am not sure why would you be concerned with where the view state shows up in your source...I mean if you are concerned with the date that you are storing in there being displayed, well its base 64 encoded so a reader can't just read it. However it's not encrypted or anything and there are base 64 decoders out there that can simply decode it for you. I hope this helps. Sam

        F Offline
        F Offline
        Fred_Smith
        wrote on last edited by
        #3

        sam L wrote:

        I am not sure why would you be concerned with where the view state shows up in your source...

        He said why, Sam: for SEO (Search Engine Optimisation) purposes. He believes, rightly or wrongly, I wouoldn't know, that having the viewstate near the top of the page, and thus "pushing" the actual content further down, means that search engines such as Google will rank it lower. I have heard that the position on the page of content can affect it's ranking, but I would also have hoped that Google et al would be smart enough to ignore viewstate.... be interesting to know for sure, I must admit though... cheers Fred

        S 1 Reply Last reply
        0
        • S sam L 0

          You can either turn the view state off for a particular control, or even for the entire page...however that's not adviceable as you won't be able to keep the state of your other controls around across post back. Now if you turn it off for the page, then when you go do source -> view, you are not going to see the view state field there. I am not sure why would you be concerned with where the view state shows up in your source...I mean if you are concerned with the date that you are storing in there being displayed, well its base 64 encoded so a reader can't just read it. However it's not encrypted or anything and there are base 64 decoders out there that can simply decode it for you. I hope this helps. Sam

          J Offline
          J Offline
          JohnyCoder
          wrote on last edited by
          #4

          Sam: Thanks for replying. Actaully i want to keep the state of the page.If i turn it off for a page, i would nt be able to do so. Its for SEO perposes (Or my boss just does not like it). I want to keep the _viewstate hidden field but i just dont want it to appear at the top of the htmlForm (in View Source) but some where at the bottom. It has to something the way page renders it controls.I may need to change the default rendering of the controls. I have a slight idea but just dont know the entry point. Thanks Aamir

          S 1 Reply Last reply
          0
          • F Fred_Smith

            sam L wrote:

            I am not sure why would you be concerned with where the view state shows up in your source...

            He said why, Sam: for SEO (Search Engine Optimisation) purposes. He believes, rightly or wrongly, I wouoldn't know, that having the viewstate near the top of the page, and thus "pushing" the actual content further down, means that search engines such as Google will rank it lower. I have heard that the position on the page of content can affect it's ranking, but I would also have hoped that Google et al would be smart enough to ignore viewstate.... be interesting to know for sure, I must admit though... cheers Fred

            S Offline
            S Offline
            sam L 0
            wrote on last edited by
            #5

            Fred, thanks for the explanation I guess I didn't pay attention to the SEO aspect of it. I did some research and found this article www.wwwcoder.com/main/parentid/457/site/6173/68/default.aspx. It seems like the popular opinion on this issue is that if you are concerned with your page's ranking by a search engine, then you may want to remove the view state completely and rely on the good ole session state. Here's another article using DNN, it tells you how to do that. www.wwwcoder.com/main/parentid/224/site/3507/68/default.aspx Sam

            1 Reply Last reply
            0
            • J JohnyCoder

              Sam: Thanks for replying. Actaully i want to keep the state of the page.If i turn it off for a page, i would nt be able to do so. Its for SEO perposes (Or my boss just does not like it). I want to keep the _viewstate hidden field but i just dont want it to appear at the top of the htmlForm (in View Source) but some where at the bottom. It has to something the way page renders it controls.I may need to change the default rendering of the controls. I have a slight idea but just dont know the entry point. Thanks Aamir

              S Offline
              S Offline
              sam L 0
              wrote on last edited by
              #6

              Aamir, check out my response above to Fred's post. sam

              J 2 Replies Last reply
              0
              • S sam L 0

                Aamir, check out my response above to Fred's post. sam

                J Offline
                J Offline
                JohnyCoder
                wrote on last edited by
                #7

                Thanks Sam: I also found some articals explaining the viewstate delima. Most of them suggest to place the viewstate in session or cache instead of page.It not only helps in improving the performance but also in page ranking( since all the junk is out of the page). Tommorow i m going to implement this idea. I will keep u posted once i am done. Thanks Aamir

                1 Reply Last reply
                0
                • S sam L 0

                  Aamir, check out my response above to Fred's post. sam

                  J Offline
                  J Offline
                  JohnyCoder
                  wrote on last edited by
                  #8

                  Hello guys. Here is the code to move _VIEWSTATE hidden field from top of the form to bottom.drop this code in the basepage and then inherit all the pages from the basepage in ur app. protected override void Render(System.Web.UI.HtmlTextWriter writer) { System.IO.StringWriter stringWriter = new System.IO.StringWriter(); HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter); base.Render(htmlWriter); string html = stringWriter.ToString(); int StartPoint = html.IndexOf("= 0) { int EndPoint = html.IndexOf("/>", StartPoint) + 2; string viewstateInput = html.Substring(StartPoint, EndPoint - StartPoint); html = html.Remove(StartPoint, EndPoint - StartPoint); int FormEndStart = html.IndexOf("") - 1; if (FormEndStart >= 0) { html = html.Insert(FormEndStart, viewstateInput } } writer.Write(html); } Thanks sam: Thank you everyone. Aamir

                  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