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. Losing viewstate ?

Losing viewstate ?

Scheduled Pinned Locked Moved ASP.NET
question
6 Posts 4 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.
  • C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #1

    I have an ascx which dynamically loads another ascx inside itself, and the inner one is losing all viewstate. I am loading it in OnLoad. Can anyone suggest why this might be ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

    P B 2 Replies Last reply
    0
    • C Christian Graus

      I have an ascx which dynamically loads another ascx inside itself, and the inner one is losing all viewstate. I am loading it in OnLoad. Can anyone suggest why this might be ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

      P Offline
      P Offline
      Paul Watson
      wrote on last edited by
      #2

      My brain is trying to remember which way around it was when I ran into this (can't remember the project to check up on). I vaguely remember that you must not re-run the code in the onload that loads the control. i.e. The viewstate will handle it, it will re-load the inner control and retain the value. If you re-load it, then it is nuking the viewstate saved control. So use IsPostBack. I can't remember why it made sense because on the face of it it doesn't. But I think that is it. regards, Paul Watson Bluegrass South Africa Brian Welsch wrote: "blah blah blah, maybe a potato?" while translating my Afrikaans. Crikey! ain't life grand?

      C 1 Reply Last reply
      0
      • P Paul Watson

        My brain is trying to remember which way around it was when I ran into this (can't remember the project to check up on). I vaguely remember that you must not re-run the code in the onload that loads the control. i.e. The viewstate will handle it, it will re-load the inner control and retain the value. If you re-load it, then it is nuking the viewstate saved control. So use IsPostBack. I can't remember why it made sense because on the face of it it doesn't. But I think that is it. regards, Paul Watson Bluegrass South Africa Brian Welsch wrote: "blah blah blah, maybe a potato?" while translating my Afrikaans. Crikey! ain't life grand?

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

        Thanks - it does not solve all my problems, but it does appear to have saved my viewstate variables in my Page_Load where I was checking them to see what was going on. One step closer to a solution, I at least have some ideas of what is going on. I am trying to impliment a generic wizard control, which uses controls as the wizard pages. What I hate about .NET compared to MFC is that they don't give you the source code. So many MFC questions were answered by stepping into the MFC source and looking at what it was doing..... Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

        P 1 Reply Last reply
        0
        • C Christian Graus

          I have an ascx which dynamically loads another ascx inside itself, and the inner one is losing all viewstate. I am loading it in OnLoad. Can anyone suggest why this might be ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

          B Offline
          B Offline
          BammBamm
          wrote on last edited by
          #4

          I believe that if you are truely dynamicaly loading a control (as opposed to just hidding and showing it) viewstate for that control will not be preserved. I believe this is because viewstate is allready loaded by the time you dynamically re-load the control. I ran into the same problem with controlls on an aspx page. My solution, which I don't truely like, was to hide and show the controls when needed. On the controls themselves I did nothing on page_load so as to keep overhead to a minimum, instead I made public functions called init() which I would call whenever I made the controls visible. If you find a better solution please let me know.

          1 Reply Last reply
          0
          • C Christian Graus

            Thanks - it does not solve all my problems, but it does appear to have saved my viewstate variables in my Page_Load where I was checking them to see what was going on. One step closer to a solution, I at least have some ideas of what is going on. I am trying to impliment a generic wizard control, which uses controls as the wizard pages. What I hate about .NET compared to MFC is that they don't give you the source code. So many MFC questions were answered by stepping into the MFC source and looking at what it was doing..... Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

            P Offline
            P Offline
            Paul Watson
            wrote on last edited by
            #5

            > is that they don't give you the source code. So many MFC questions were answered by stepping into the MFC source and looking at what it was doing..... By source do you mean the IL code generated for your application, or the code that makes up the .NET Framework? I am out of my depth here but I believe either way you can get an IL disasembler to view this kind of code. .NET comes with one, ILDasm.exe, and there is one here on CP. David Stone is into this kind of thing AFAIR. Debugging .NET Framework and MS Visual Studio Managed Classes at Run time and Design time might be of use and the tool it mentions, Reflector.NET. Apologies if I am barking up the wrong tree :) regards, Paul Watson Bluegrass South Africa Brian Welsch wrote: "blah blah blah, maybe a potato?" while translating my Afrikaans. Crikey! ain't life grand?

            J 1 Reply Last reply
            0
            • P Paul Watson

              > is that they don't give you the source code. So many MFC questions were answered by stepping into the MFC source and looking at what it was doing..... By source do you mean the IL code generated for your application, or the code that makes up the .NET Framework? I am out of my depth here but I believe either way you can get an IL disasembler to view this kind of code. .NET comes with one, ILDasm.exe, and there is one here on CP. David Stone is into this kind of thing AFAIR. Debugging .NET Framework and MS Visual Studio Managed Classes at Run time and Design time might be of use and the tool it mentions, Reflector.NET. Apologies if I am barking up the wrong tree :) regards, Paul Watson Bluegrass South Africa Brian Welsch wrote: "blah blah blah, maybe a potato?" while translating my Afrikaans. Crikey! ain't life grand?

              J Offline
              J Offline
              J Dunlap
              wrote on last edited by
              #6

              Paul Watson wrote: Reflector.NET. Excellent tool! I wanted to know what was going on behind the scenes in a method of System.Windows.Forms.Forms, and all I had to do was open it and click on the method, and there was the source code! You can view the source in C#, VB.NET, and MC++.

              **"But the fruit of the Spirit is love, joy, peace, patience, kindness, goodness..." -- Galatians 5:22-23b

              FLUID UI Toolkit | FloodFill in C# & GDI+**

              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