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. Disabled controls don't maintain state

Disabled controls don't maintain state

Scheduled Pinned Locked Moved ASP.NET
csharphelpannouncement
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.
  • K Offline
    K Offline
    krisp
    wrote on last edited by
    #1

    I have some radio buttons, I set them to disabled in codebehind, this way the user has only a readonly version of the page controls. However when the page postsback they loose their state. No radio buttons are checked. Usually if the control is enabled upon postback then: Page.Request.Form["myRadioButton2"] == "on" And the ASP .Net engine/parser sets myRadioButton2.Checked = true; However, this Name/Value pair is not in the Page.Request.Form Name/Value collection whenever the control is posted back in a disabled state. I even save its state in SaveViewState() and load it in LoadViewState(); it loads the correct values at first, but then when OnLoad is reached, the ASP .Net engine/parser has sets its state back to the default (Checked = false). Any help on this would be much appreciated. I have this probelm occurring in many areas with many other controls. Always when controls are disabled. CheckBoxLists loose state, DropDownLists loose state as well. Thanks!

    J 1 Reply Last reply
    0
    • K krisp

      I have some radio buttons, I set them to disabled in codebehind, this way the user has only a readonly version of the page controls. However when the page postsback they loose their state. No radio buttons are checked. Usually if the control is enabled upon postback then: Page.Request.Form["myRadioButton2"] == "on" And the ASP .Net engine/parser sets myRadioButton2.Checked = true; However, this Name/Value pair is not in the Page.Request.Form Name/Value collection whenever the control is posted back in a disabled state. I even save its state in SaveViewState() and load it in LoadViewState(); it loads the correct values at first, but then when OnLoad is reached, the ASP .Net engine/parser has sets its state back to the default (Checked = false). Any help on this would be much appreciated. I have this probelm occurring in many areas with many other controls. Always when controls are disabled. CheckBoxLists loose state, DropDownLists loose state as well. Thanks!

      J Offline
      J Offline
      Jon G
      wrote on last edited by
      #2

      One option would be to save the checkbox states into a Session variable. It is probably not the best way, but it would result in a solution to the problem. for example: Session("CheckBox1") = CheckBox1.Checked Then, when you reload your page, in Page_Load: if Page.IsPostBack then CheckBox1.Checked = Session("CheckBox1") end if Jon G www.Gizmocoder.com

      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