Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Adam Jenkin 71 posts 226 karma points
    Dec 19, 2011 @ 16:07
    Adam Jenkin
    0

    Viewstate - Can I access use this with Razor?

    I need to use viewstate to persist a counter on a page during postbacks (im working on a form of an alternating content control so I need to track the last item viewed in order to know which one to display next time around).

    Its 4.7.1, so its webforms, therefore I think it should be available, however I cannot figure our how to access it as from my cshtml, I dont have any current page context/reference.

    I can use session state (through the current HTTP Context), but I dont really want to! :P

    Can anyone help?

    Adam

  • awm 187 posts 376 karma points
    Dec 19, 2011 @ 16:22
    awm
    1

    I wouldn't have thought you'd want to be doing this through razor (I'm not sure it's intended for this?). Maybe you should use a .NET user control?

  • Adam Jenkin 71 posts 226 karma points
    Dec 19, 2011 @ 17:05
    Adam Jenkin
    0

    Thats a fair point! This is my first project using razor - Im probably being blinded by the new stuff! 

  • awm 187 posts 376 karma points
    Dec 19, 2011 @ 17:11
    awm
    0

    Ah I wouldn't worry, I did the same thing! I think the natural inclination is to try and use razor to do everything when the reality is, it's only supposed to add a touch of functionality instead of doing any heavy duty stuff... leave that to the user controls :-)

  • Barry Fogarty 493 posts 1129 karma points
    Dec 19, 2011 @ 18:09
    Barry Fogarty
    1

    How about using a cookie to store the value?  No problem reading and writing from your CSHTML via the Response.Cookies (to write) and the Request.Cookies (to read) collections.

    I like the way how razor helps me to leave beind the old ASP.Net server control model and go back to good ol' HTTP.  Also this will be good grounding if you intend to get on the MVC bandwagon for Umbraco v5.

  • Adam Jenkin 71 posts 226 karma points
    Dec 19, 2011 @ 18:36
    Adam Jenkin
    0

    I was thinking I could perhaps use an "<input type="hidden" ..." which is what viewstate is anyway! A cookie would work also - but am thinking that the correct route is not razor for this particular problem. 

Please Sign in or register to post replies

Write your reply to:

Draft