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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. CheckBoxList and PostBack

CheckBoxList and PostBack

Scheduled Pinned Locked Moved ASP.NET
helpquestion
5 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.
  • A Offline
    A Offline
    Ahmed Galal
    wrote on last edited by
    #1

    i have a CheckBoxList inside a DataList, i bind the CheckBoxList in the DataList ItemDataBound event, everything is working fine except that i lose the datasource of the checkboxlist within any postback, i bind my datalist in the Page_Load event inside if(!IsPostBack) .. i know i could bind my datalist outside this if condition and that should make it work, but it will cause re-loading the data every postback beside i did some clientside scripting that lets the user manipulate some controls without postback, so the data will not look the same if i reloaded it everytime. i hope theres a solution or any workaround any help ? thanks in advance.

    T 1 Reply Last reply
    0
    • A Ahmed Galal

      i have a CheckBoxList inside a DataList, i bind the CheckBoxList in the DataList ItemDataBound event, everything is working fine except that i lose the datasource of the checkboxlist within any postback, i bind my datalist in the Page_Load event inside if(!IsPostBack) .. i know i could bind my datalist outside this if condition and that should make it work, but it will cause re-loading the data every postback beside i did some clientside scripting that lets the user manipulate some controls without postback, so the data will not look the same if i reloaded it everytime. i hope theres a solution or any workaround any help ? thanks in advance.

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      The checkboxlist data should remain even after a post back as long as you are not rebinding the DataList. Any changes you make via javascript will be undone after a postback because the page will re-render the original html of the control. One trick around this is to set the value of hidden fields in javascript and then during the postback check those hidden fields and do the same work with server side code that you did with javascript.

      I didn't get any requirements for the signature

      A 1 Reply Last reply
      0
      • T ToddHileHoffer

        The checkboxlist data should remain even after a post back as long as you are not rebinding the DataList. Any changes you make via javascript will be undone after a postback because the page will re-render the original html of the control. One trick around this is to set the value of hidden fields in javascript and then during the postback check those hidden fields and do the same work with server side code that you did with javascript.

        I didn't get any requirements for the signature

        A Offline
        A Offline
        Ahmed Galal
        wrote on last edited by
        #3

        i think the checkboxlist has a problem, i know that the datasource should remain after post backs and thats all controls do except the checkboxlist, i dunno and yea, i do set attributes and hidden fields to read the data and it works fine, the problem is that i cant read the datasource of the checkboxlist after postbacks. any idea ? thanks for replying

        T 1 Reply Last reply
        0
        • A Ahmed Galal

          i think the checkboxlist has a problem, i know that the datasource should remain after post backs and thats all controls do except the checkboxlist, i dunno and yea, i do set attributes and hidden fields to read the data and it works fine, the problem is that i cant read the datasource of the checkboxlist after postbacks. any idea ? thanks for replying

          T Offline
          T Offline
          ToddHileHoffer
          wrote on last edited by
          #4

          The only thing I can think of is to use a DataTable as the checkbox list's source and store the datatable in viewstate. Then you can rebind it on every postback if you must.

          I didn't get any requirements for the signature

          A 1 Reply Last reply
          0
          • T ToddHileHoffer

            The only thing I can think of is to use a DataTable as the checkbox list's source and store the datatable in viewstate. Then you can rebind it on every postback if you must.

            I didn't get any requirements for the signature

            A Offline
            A Offline
            Ahmed Galal
            wrote on last edited by
            #5

            yea i think too ... thanks much for ur time.

            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