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