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. Save int on page with Viewstate

Save int on page with Viewstate

Scheduled Pinned Locked Moved ASP.NET
help
3 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.
  • A Offline
    A Offline
    abbd
    wrote on last edited by
    #1

    Hi, i would saving a int in variable, When there is the post of variable, I want this record remains variable in the page despite updating the page, I do as follows:

    public string s;

    protected void Page_Load(object sender, EventArgs e)
    { if (Request.Form["champ"] != "")
    { s = Request.Form["champ"]; }

        ViewState\["s"\] = s;
        string s1 = ViewState\["s"\].ToString();
    

    }

    an error was shows : The reference object is not defined by an instance of an object , on line : string s1 = ViewState["s"].ToString(); Please help me to resolve this great problem, thank you very mutch.

    M N 2 Replies Last reply
    0
    • A abbd

      Hi, i would saving a int in variable, When there is the post of variable, I want this record remains variable in the page despite updating the page, I do as follows:

      public string s;

      protected void Page_Load(object sender, EventArgs e)
      { if (Request.Form["champ"] != "")
      { s = Request.Form["champ"]; }

          ViewState\["s"\] = s;
          string s1 = ViewState\["s"\].ToString();
      

      }

      an error was shows : The reference object is not defined by an instance of an object , on line : string s1 = ViewState["s"].ToString(); Please help me to resolve this great problem, thank you very mutch.

      M Offline
      M Offline
      MoustafaS
      wrote on last edited by
      #2

      Set it as a hiddenfield server control.

      1 Reply Last reply
      0
      • A abbd

        Hi, i would saving a int in variable, When there is the post of variable, I want this record remains variable in the page despite updating the page, I do as follows:

        public string s;

        protected void Page_Load(object sender, EventArgs e)
        { if (Request.Form["champ"] != "")
        { s = Request.Form["champ"]; }

            ViewState\["s"\] = s;
            string s1 = ViewState\["s"\].ToString();
        

        }

        an error was shows : The reference object is not defined by an instance of an object , on line : string s1 = ViewState["s"].ToString(); Please help me to resolve this great problem, thank you very mutch.

        N Offline
        N Offline
        nyeboy
        wrote on last edited by
        #3

        string s1=(string)ViewState["s"];

        studing is processing in this life.

        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