473,287 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Displaying datasources modified by postback events without server.transfer or response.redirect

RAJ
In our multi-tier application, we have several ASP.NET user controls which
will update the same data source provided by middle tier logic.

In this particular scenario we have one user control displaying the contents
of the data source, whilst another control updates the datasource via a
command buttons implementation of 'Click', an event raised in the 'Handle
Postback Events' stage of the control execution life cycle (via the
RaisePostBackEvent method).

These user controls are structured at present, in the Page_Load event,
including the control which is concerned only with displaying the datasource
contents. The problem therefore is that if the control has already been
structured for rendering, and the datasource is updated afterwards, then the
changes to the datasource are not present in the displaying control, but are
present in the updating control.

Now seeing as though the command button constituent controls (which
implement the IPostBackDataHandler marker interface) are instantiated
straight from Page_Init (regardless to their presence in the designer or
created manually for composition), then even if the rest of the control
isn't structured in Page_Load, during the 'Handle Postback Events' stage of
the control execution life cycle, this control would still perform its
'Click' event?

Please also consider the following factors:

.. Either control is capable of updating the data source (so one may be the
updater, the other the displayer, and vice versa)

.. The 'Load' phase of the controls execution life cycle states: 'At this
point, server controls in the tree are created and initialized, the state is
restored, and form controls reflect client-side data.'.

.. The controls execution life cycle also states: 'The CreateChildControls
method is not listed in the table because it is called whenever the ASP.NET
page framework needs to create the controls tree and this method call is not
limited to a specific phase in a control's lifecycle. For example,
CreateChildControls can be invoked when loading a page, during data binding
or during rendering.'.

Is it therefore possible to 'EnsureChildControls' from the 'Click' event of
the updating controls command button, create the input controls which had
taken part in the post-back process, obtain the postback data from these
input controls (Note that at this point, the 'Load' phase has already run!
Have these controls missed out their viewstate and postback processing
stage?!?) and update the datasource?

Likewise if this control is not updating the datasource, is it safe to
assume that it would be possible to render the displaying control in
CreateChildControls, which is ensured (EnsureChildControls) from the
PreRender event?

This would remove the requirement for either a Server.Transfer or
Response.Redirect from the command buttons 'Click' event, of which the
former is difficult to cater for (because it retains the original
HTTPRequest, disabling different user controls ability to structure URLs
correctly), and the latter which causes an additional round trip to client
and server.

Any insight into this perplexing problem would be greatly appreciated!

Thanks

RAJ
Nov 18 '05 #1
2 4272
this is way there are prerender and render events. your bound controls
should use the value of the datasource at render time, not load. this allows
init, load and postback events to change the value and still have it render
correctly.

-- bruce (sqlwork.com)
"RAJ" <an*******@discussions.microsoft.com> wrote in message
news:O5**************@TK2MSFTNGP12.phx.gbl...
In our multi-tier application, we have several ASP.NET user controls which
will update the same data source provided by middle tier logic.

In this particular scenario we have one user control displaying the contents of the data source, whilst another control updates the datasource via a
command buttons implementation of 'Click', an event raised in the 'Handle
Postback Events' stage of the control execution life cycle (via the
RaisePostBackEvent method).

These user controls are structured at present, in the Page_Load event,
including the control which is concerned only with displaying the datasource contents. The problem therefore is that if the control has already been
structured for rendering, and the datasource is updated afterwards, then the changes to the datasource are not present in the displaying control, but are present in the updating control.

Now seeing as though the command button constituent controls (which
implement the IPostBackDataHandler marker interface) are instantiated
straight from Page_Init (regardless to their presence in the designer or
created manually for composition), then even if the rest of the control
isn't structured in Page_Load, during the 'Handle Postback Events' stage of the control execution life cycle, this control would still perform its
'Click' event?

Please also consider the following factors:

. Either control is capable of updating the data source (so one may be the
updater, the other the displayer, and vice versa)

. The 'Load' phase of the controls execution life cycle states: 'At this
point, server controls in the tree are created and initialized, the state is restored, and form controls reflect client-side data.'.

. The controls execution life cycle also states: 'The CreateChildControls
method is not listed in the table because it is called whenever the ASP.NET page framework needs to create the controls tree and this method call is not limited to a specific phase in a control's lifecycle. For example,
CreateChildControls can be invoked when loading a page, during data binding or during rendering.'.

Is it therefore possible to 'EnsureChildControls' from the 'Click' event of the updating controls command button, create the input controls which had
taken part in the post-back process, obtain the postback data from these
input controls (Note that at this point, the 'Load' phase has already run!
Have these controls missed out their viewstate and postback processing
stage?!?) and update the datasource?

Likewise if this control is not updating the datasource, is it safe to
assume that it would be possible to render the displaying control in
CreateChildControls, which is ensured (EnsureChildControls) from the
PreRender event?

This would remove the requirement for either a Server.Transfer or
Response.Redirect from the command buttons 'Click' event, of which the
former is difficult to cater for (because it retains the original
HTTPRequest, disabling different user controls ability to structure URLs
correctly), and the latter which causes an additional round trip to client
and server.

Any insight into this perplexing problem would be greatly appreciated!

Thanks

RAJ

Nov 18 '05 #2
RAJ
Thanks for your reply.
Apologies for length!

Its my understanding that the control hierarchy has to be reconstructed in
Load so that the controls which formed part of the previous response are
populated with the postback data.

From what I've read in MSDN, the controls have their viewstate restored
based on their position in the control hierarchy, and viewstate is just a
dictionary indexed by the individual control's Unique ID. The same, as far
as I know; applies to postback data.

As a consequence, the control modifying the datasource has to be rebuilt
once for restoring viewstate and capturing postback data, and a second time
for displaying the updated data source changed as a result of postback data
modifications.

MSDN also states in the Control Execution Lifecycle that
'CreateChildControls' is not called at any specific stage. It can be
guaranteed however, to run when an internal call to FindControl is invoked,
the related instance of which probes the 'Controls' collection property, all
of which is part of the viewstate restoration process!

Interestingly, the 'ChildControlsCreated' property is not readonly, so this
can be set to false at any point to allow 'EnsureChildControls' to re-render
the composite controls. As a consequence of running 'CreateChildControls'
twice, the Controls collection has to be cleared.

Unfortunately, after clearing the controls collection, controls which have a
half-half implementation in design and composition in code behind will not
restore controls loaded from the designer, even if the base
'CreateChildControls' method is called.

This is because the designer control structure is built from the
automatically generated FrameworkInitialize function which invokes the
__BuildControlTree method, declared in the 'controlname_ascx' class, which
inherits from the class definition declared in the related code behind file!

Thankfully due to the inheritance hierarchy, FrameworkInitialize is
overridden by the 'controlname_ascx' subclass which in turn re-parses the
ascx layout, allowing it to be invoked from CreateChildControls. But this
doesn't appear to be a supported method, and isn't documented in MSDN.

Is it wise to perform FrameworkInitialize from the CreateChildControls
function?

This is what I plan to implement:

1) Load View State stage automatically invokes CreateChildControls
(FrameworkInitialize is called twice at this point already), building the
control structure which is a replica of the previous response
2) Controls are populated with postback data
3) Load is invoked where pretty much nothing happens
4) The control which handles the post back fires the appropriate event
5) The datasource is updated as a result of postback data
6) ChildControlsCreated is set to false
7) PreRender calls EnsureChildControls
8) CreateChildControls is run a second time re-structuring the entire
control
9) Tear-down and dispose

RAJ

"bruce barker" <no***********@safeco.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
this is way there are prerender and render events. your bound controls
should use the value of the datasource at render time, not load. this allows init, load and postback events to change the value and still have it render correctly.

-- bruce (sqlwork.com)
"RAJ" <an*******@discussions.microsoft.com> wrote in message
news:O5**************@TK2MSFTNGP12.phx.gbl...
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic.

In this particular scenario we have one user control displaying the contents
of the data source, whilst another control updates the datasource via a
command buttons implementation of 'Click', an event raised in the 'Handle Postback Events' stage of the control execution life cycle (via the
RaisePostBackEvent method).

These user controls are structured at present, in the Page_Load event,
including the control which is concerned only with displaying the

datasource
contents. The problem therefore is that if the control has already been
structured for rendering, and the datasource is updated afterwards, then

the
changes to the datasource are not present in the displaying control, but

are
present in the updating control.

Now seeing as though the command button constituent controls (which
implement the IPostBackDataHandler marker interface) are instantiated
straight from Page_Init (regardless to their presence in the designer or
created manually for composition), then even if the rest of the control
isn't structured in Page_Load, during the 'Handle Postback Events' stage

of
the control execution life cycle, this control would still perform its
'Click' event?

Please also consider the following factors:

. Either control is capable of updating the data source (so one may be the updater, the other the displayer, and vice versa)

. The 'Load' phase of the controls execution life cycle states: 'At this
point, server controls in the tree are created and initialized, the state is
restored, and form controls reflect client-side data.'.

. The controls execution life cycle also states: 'The

CreateChildControls method is not listed in the table because it is called whenever the

ASP.NET
page framework needs to create the controls tree and this method call is

not
limited to a specific phase in a control's lifecycle. For example,
CreateChildControls can be invoked when loading a page, during data

binding
or during rendering.'.

Is it therefore possible to 'EnsureChildControls' from the 'Click' event

of
the updating controls command button, create the input controls which had taken part in the post-back process, obtain the postback data from these
input controls (Note that at this point, the 'Load' phase has already run! Have these controls missed out their viewstate and postback processing
stage?!?) and update the datasource?

Likewise if this control is not updating the datasource, is it safe to
assume that it would be possible to render the displaying control in
CreateChildControls, which is ensured (EnsureChildControls) from the
PreRender event?

This would remove the requirement for either a Server.Transfer or
Response.Redirect from the command buttons 'Click' event, of which the
former is difficult to cater for (because it retains the original
HTTPRequest, disabling different user controls ability to structure URLs
correctly), and the latter which causes an additional round trip to client and server.

Any insight into this perplexing problem would be greatly appreciated!

Thanks

RAJ


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: \A_Michigan_User\ | last post by:
Ok, I give up... why do 1-4 work fine... but 5-6 give "can't find" errors? 1. Client-side VBscript code: call navigate("\\209.11.22.33\MyDir") 2. Client-side VBscript code: location.href...
4
by: Harsh Thakur | last post by:
Hi, I'd like to know the performance related differences between Response.Redirect and Server.Transfer. I'd like to redirect the user to a different page. I can either do a...
5
by: John W | last post by:
Hello, I have been wondering that everytime I do a submit on a button/form (postback) it is using the same webform on the CS, how do I goto another webform once I have done a postback and...
3
by: Alan Silver | last post by:
Hello, Sorry if this is a stupid question, but I can't really see much difference between these tow methods according to the scant info in the SDK. Could anyone enlighten me? TIA -- Alan...
6
by: Gauthier Segay | last post by:
Hello, I've problem on subsequent postbacks after a Server.Transfer was done. In our application framework we have a method that pass parameters (via HttpContext.Items) and navigate to another...
6
by: Coleen | last post by:
Hi all :-) I need to redirect to multiple pages on click of a transmit button, without redisplaying each page. This redirection is to capture session variables that are created on each page and...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
3
by: Uriah Piddle | last post by:
Hi Gang, As far as transferring data goes, is putting a context.response.redirect statement in an event handler basically the same as setting the PostBackUrl prop for a control? So far, none of...
9
by: RN1 | last post by:
When a server encounters the line Response.Redirect("abcd.asp") in a ASP script, the server tells the browser that it has to be redirected to another page (which is abcd.asp, in this case)....
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.