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. General Programming
  3. C#
  4. Static Controls

Static Controls

Scheduled Pinned Locked Moved C#
helpdesign
2 Posts 2 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.
  • T Offline
    T Offline
    TheMajorRager
    wrote on last edited by
    #1

    Hello Everyone. I was wondering is there a way to make a CONTROL static like this: public static System.Web.UI.WebControls.Label errorlabel = new Label(); I tried that but I got an error message when the program ran. My problem is that label, errorlabel should contain an error message on it, but if I click a certain button, and then I click back, the errorLabel does not get set back to "" because it does not go to the Page_Load when you click back. So instead the error message again pops back up when you click back and I dont want that to happen. What I was trying to do was when I go to the next page, since it would be accessable to the that page since it's static, to change it there to the empty string. So if anyone can help, I would really appreciate it. Thanks, TheMajorRager

    C 1 Reply Last reply
    0
    • T TheMajorRager

      Hello Everyone. I was wondering is there a way to make a CONTROL static like this: public static System.Web.UI.WebControls.Label errorlabel = new Label(); I tried that but I got an error message when the program ran. My problem is that label, errorlabel should contain an error message on it, but if I click a certain button, and then I click back, the errorLabel does not get set back to "" because it does not go to the Page_Load when you click back. So instead the error message again pops back up when you click back and I dont want that to happen. What I was trying to do was when I go to the next page, since it would be accessable to the that page since it's static, to change it there to the empty string. So if anyone can help, I would really appreciate it. Thanks, TheMajorRager

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      TheMajorRager wrote:

      My problem is that label, errorlabel should contain an error message on it, but if I click a certain button, and then I click back, the errorLabel does not get set back to "" because it does not go to the Page_Load when you click back

      This is ASP.NET ? It won't work. Your control is recreated on every post back, no matter what. You need to store the text in viewstate, and restore it, assuming the control is incapable of doing this for you.

      TheMajorRager wrote:

      What I was trying to do was when I go to the next page, since it would be accessable to the that page since it's static, to change it there to the empty string.

      When you move to another page, all contact with the class instance that was running the last page is lost. You have to remember in ASP.NET, you don't get one class instance for the page, you get one every time the page is rendered, which is brand new, unless it's a postback, and then it is still brand new, but can repopulate some fields from viewstate. Christian Graus - Microsoft MVP - C++

      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