Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   ViewState, XML and XSLT (http://www.velocityreviews.com/forums/t775134-viewstate-xml-and-xslt.html)

CJ de Vos 01-06-2005 08:16 AM

ViewState, XML and XSLT
 
Hi,
I'm using XML and XSLT to format my HTML. After a postback I recreate all
controls as soon as possible (OnInit and after the LoadViewstate). After the
recreation all events are handled correctly. However, some events make
adjustments to the XML. Because of this changed XML I need to recreate all
controls again using the XSLT. This works. The problem arises with the
viewstate, which I am not able to reload. Is there anything I can do to load
the viewstate of the controls.
I already solved this for the Posted data using the
IPostbackDataEventHandler, but I'm stuck with the viewstate. Please note
that I try to not uyse another __postback call.

I already thought of storing the ViewState property of each control
(recursively), but unfortunately this property is Protected. Otherwise I
could have done something like:
Dim sb as New StateBag()
sb.Add(c.UniqueID, CType(Control.ViewState, IStateManager).SaveViewState())
and
CType(Control.ViewState, IStateManager).LoadViewState(sb.Item(c.UniqueID))

Right now I'm thinking along I could try calling the
LoadPageStateFromPersistenceMedium, but am not sure whether this will work
or not.

Does anybody have a good idea or alternative?

Kind regards,
CJ.




Dimitri Glazkov 01-06-2005 02:27 PM

Re: ViewState, XML and XSLT
 
Can you explain why you are trying to recreate all controls as soon as
possible?

:DG<

"CJ de Vos" <aspnetquestion@cdevos.nl> wrote in message
news:592fb$41dcf347$3e3a082a$15130@news1.versatel. nl...
> Hi,
> I'm using XML and XSLT to format my HTML. After a postback I recreate all
> controls as soon as possible (OnInit and after the LoadViewstate). After
> the
> recreation all events are handled correctly. However, some events make
> adjustments to the XML. Because of this changed XML I need to recreate all
> controls again using the XSLT. This works. The problem arises with the
> viewstate, which I am not able to reload. Is there anything I can do to
> load
> the viewstate of the controls.
> I already solved this for the Posted data using the
> IPostbackDataEventHandler, but I'm stuck with the viewstate. Please note
> that I try to not uyse another __postback call.
>
> I already thought of storing the ViewState property of each control
> (recursively), but unfortunately this property is Protected. Otherwise I
> could have done something like:
> Dim sb as New StateBag()
> sb.Add(c.UniqueID, CType(Control.ViewState,
> IStateManager).SaveViewState())
> and
> CType(Control.ViewState, IStateManager).LoadViewState(sb.Item(c.UniqueID))
>
> Right now I'm thinking along I could try calling the
> LoadPageStateFromPersistenceMedium, but am not sure whether this will work
> or not.
>
> Does anybody have a good idea or alternative?
>
> Kind regards,
> CJ.
>
>
>




CJ de Vos 01-06-2005 05:09 PM

Re: ViewState, XML and XSLT
 
This is a continuation of a discussion between dimitri and myself. Please
note that the problem still remains. Plus an extra related question has been
added. Being: how does Microsoft make sure that the viewstate is restored
per control.


------------------------------------------------------------------

Too much luck that we are both creating an XML based CMS ;-) You will have
to show me yours when you have a demo version!



The first simple solution I had was by implementing the
IpostBackEventHandler interface, and made a call to the javascript
__doPostBack(Me.UniqueID, "rebind") call. Of course this will work, but
requires an additional reload of the page. This is not user friendly.

A redirect cannot work for any viewstate of controls other than the
'webdocument editor control' will not be restored, nor will any posted data
be.

I'm trying to avoid this situation.



Like I said before. Right now I have an option in my custom controls that
stores any information back into the XML document, and then rebind with this
updated XML document. This approach is also far from perfect, but does work
and does not require a postback.



I guess that it is either impossible, or the MSDN docs do not contain all
information 'we' need.



I'm really wondering how Microsoft makes sure that the viewstate is restored
per control.









CJ de Vos

Hemels van der Hart - http://www.hvdh.nl

T 030-282 99 65

F 030-282 99 98

E cdevos@hvdh.nl



-----Original Message-----
From: Dimitri Glazkov [mailto:dimitri.glazkov@gmail.com]
Sent: Thursday, January 06, 2005 5:44 PM
To: CJ de Vos
Subject: Re: ViewState, XML and XSLT



CJ,



Well, what do you know? I am also working on an XML-based CMS :) Maybe

we should collaborate :)



The solution to your problem is in making the work your pages do more

granular from request to request.



Have you ever wondered why this is so hard? Well, that's because the

rebuilding of the XML tree and rendering of the page should not be

processed in the same tree.



What you need to do is split them up. As soon as the modification of

the tree is detected, your application simply needs to stop processing

and redirect to itself. Voila! You will have all of your processing

pains disappear and control tree refresh "automagically".



Does this make any sense? What do you think of this solution?



:DG<



On Thu, 6 Jan 2005 17:30:02 +0100, CJ de Vos <cdevos@hvdh.nl> wrote:

> Unfortunately I cannot give you any sample code, but I can give you a


> textual example.


>


> The application I am working on is an XML based CMS. Per document within


> the CMS any number of fields can exist. These fields are defined by a


> templating system, but does not concern this question.


>


> Sometimes it is necessary to add an XML element, for example a list of


> links to related websites. The editor can therefore click the 'Add' -


> button to add a specific link. After all information has been filled,


> the link is added to the xml and controls are recreated for the user to


> see. Because of this Add functionality there should also be a remove


> functionality.


>


> Since editors are usually 'dumb' we use XSLT to provide for a generic


> user interface in which we can change the output html.


>


> Events vary from LinkButton.Click to DropDownList.SelectedIndexChanged.


> it doesn't really matter what kind of event.


>


> Is this enough information?


>


> Thanks for helping out!


>


> CJ de Vos


> Hemels van der Hart - http://www.hvdh.nl


> T 030-282 99 65


> F 030-282 99 98


> E cdevos@hvdh.nl


>


> -----Original Message-----


> From: Dimitri Glazkov [mailto:dimitri.glazkov@gmail.com]


> Sent: Thursday, January 06, 2005 5:18 PM


> To: CJ de Vos


> Subject: Re: ViewState, XML and XSLT


>


> I see. The problem is much more complex than I originally thought.


>


> Could you give me an example of why the controls would need to be


> removed and which events would cause the removal?


>


> :DG<


>


> On Thu, 6 Jan 2005 17:14:09 +0100, CJ de Vos <cdevos@hvdh.nl> wrote:


> > Hi Dimitri,


> >


> > Thanks for your comment.


> >


> > I know about the method CreateChildControls method, and I use it


> > extensively in all my webcontrols.


> > This control is different though. Let me explain why.


> >


> > The XML contains information about the controls it should render.


> There


> > can be any number of controls, all dynamic and unknown until the XML


> is


> > available. The XML is passed to the datasource, and the databind will


> > make sure all controls are created. The XML is cached to be re-used


> > after any postback occurs.


> > When a postback happens, this XML is retrieved from cache again. And


> all


> > these controls are recreated. It does not matter whether I use the


> > CreateChildControls and EnsureChildControls methods or the OnInit


> event.


> > Because the controls WILL exist before the viewstate is loaded and


> > events are fired. This all works like it should.


> >


> > However. Some of these events require that controls are removed. Since


> I


> > do not know which controls were added through the XSLT, I need to


> remove


> > the actual XML element from the XML document. No controls are removed


> at


> > this stage. The only way to remove the controls is by recreating all


> > controls through XML and XSLT again.


> >


> > The problem in this case is that the LoadViewState method is not


> called


> > again, and ViewState is lost. Therefore I somehow need to call


> > SaveViewState of all controls so I can restore them after the controls


> > are recreated.


> >


> > Does this make sense to you?


> >


> > I did solve it on the short term for my own custom controls. But I


> > cannot ensure that label's and other controls which make use of the


> > viewstate will work properly when I need to do a rebind.


> >


> > Thanks in advance if you can tell me how you made the above work.


> >


> > CJ de Vos


> > Hemels van der Hart - http://www.hvdh.nl


> > T 030-282 99 65


> > F 030-282 99 98


> > E cdevos@hvdh.nl


> >


> > -----Original Message-----


> > From: Dimitri Glazkov [mailto:dimitri.glazkov@gmail.com]


> > Sent: Thursday, January 06, 2005 3:59 PM


> > To: CJ de Vos


> > Subject: Re: ViewState, XML and XSLT


> >


> > CJ,


> >


> > All you need to do is override the CreateChildControls method and


> > create your controls there. That will ensure that the controls are


> > created in time for events and viewstate handling.


> >


> > The reason why I know this is because we use a very similar idea in


> > our framework, XML + XSLT = XHTML, based on ASP.NET controls and


> > everything works just fine.


> >


> > :DG<


> >


> > On Thu, 6 Jan 2005 15:56:48 +0100, CJ de Vos <cdevos@hvdh.nl> wrote:


> > > I create controls dynamically. If I want events to be fired, or the


> > > viewstate to be loaded these controls have to be recreated as soon


> as


> > > possible (OnInit or OnLoad). This is required for all controls that


> > are


> > > loaded dynamically.


> > >


> > > "Dimitri Glazkov" <dimitri.glazkov@gmail.com> wrote in message


> > > news:<uXQnfv$8EHA.3416@TK2MSFTNGP09.phx.gbl>...


> > > > Can you explain why you are trying to recreate all controls as


> soon


> > as


> > > > possible?


> > > >


> > > > :DG<


> > > >


> > > > "CJ de Vos" <aspnetquestion@cdevos.nl> wrote in message


> > > > news:592fb$41dcf347$3e3a082a$15130@news1.versatel. nl...


> > > > > Hi,


> > > > > I'm using XML and XSLT to format my HTML. After a postback I


> > > > > recreate all controls as soon as possible (OnInit and after the


> > > > > LoadViewstate). After the recreation all events are handled


> > > > > correctly. However, some events make adjustments to the XML.


> > Because


> > >


> > > > > of this changed XML I need to recreate all controls again using


> > the


> > > > > XSLT. This works. The problem arises with the viewstate, which I


> > am


> > > > > not able to reload. Is there anything I can do to load


> > > > > the viewstate of the controls.


> > > > > I already solved this for the Posted data using the


> > > > > IPostbackDataEventHandler, but I'm stuck with the viewstate.


> > Please


> > > note


> > > > > that I try to not uyse another __postback call.


> > > > >


> > > > > I already thought of storing the ViewState property of each


> > control


> > > > > (recursively), but unfortunately this property is Protected.


> > > > > Otherwise I could have done something like: Dim sb as New


> > StateBag()


> > > > > sb.Add(c.UniqueID, CType(Control.ViewState,


> > > > > IStateManager).SaveViewState())


> > > > > and


> > > > > CType(Control.ViewState,


> > > IStateManager).LoadViewState(sb.Item(c.UniqueID))


> > > > >


> > > > > Right now I'm thinking along I could try calling the


> > > > > LoadPageStateFromPersistenceMedium, but am not sure whether this


> > > > > will work or not.


> > > > >


> > > > > Does anybody have a good idea or alternative?


> > > > >


> > > > > Kind regards,


> > > > > CJ.


> > > > >


> > > > >


> > > > >


> > > >


> > > >


> > >


> >


>



"Dimitri Glazkov" <dimitri.glazkov@gmail.com> wrote in message
news:uXQnfv$8EHA.3416@TK2MSFTNGP09.phx.gbl...
> Can you explain why you are trying to recreate all controls as soon as
> possible?
>
> :DG<
>
> "CJ de Vos" <aspnetquestion@cdevos.nl> wrote in message
> news:592fb$41dcf347$3e3a082a$15130@news1.versatel. nl...
> > Hi,
> > I'm using XML and XSLT to format my HTML. After a postback I recreate

all
> > controls as soon as possible (OnInit and after the LoadViewstate). After
> > the
> > recreation all events are handled correctly. However, some events make
> > adjustments to the XML. Because of this changed XML I need to recreate

all
> > controls again using the XSLT. This works. The problem arises with the
> > viewstate, which I am not able to reload. Is there anything I can do to
> > load
> > the viewstate of the controls.
> > I already solved this for the Posted data using the
> > IPostbackDataEventHandler, but I'm stuck with the viewstate. Please note
> > that I try to not uyse another __postback call.
> >
> > I already thought of storing the ViewState property of each control
> > (recursively), but unfortunately this property is Protected. Otherwise I
> > could have done something like:
> > Dim sb as New StateBag()
> > sb.Add(c.UniqueID, CType(Control.ViewState,
> > IStateManager).SaveViewState())
> > and
> > CType(Control.ViewState,

IStateManager).LoadViewState(sb.Item(c.UniqueID))
> >
> > Right now I'm thinking along I could try calling the
> > LoadPageStateFromPersistenceMedium, but am not sure whether this will

work
> > or not.
> >
> > Does anybody have a good idea or alternative?
> >
> > Kind regards,
> > CJ.
> >
> >
> >

>
>





All times are GMT. The time now is 12:31 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.