Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Event Sequence

Reply
Thread Tools

Event Sequence

 
 
Axel Dahmen
Guest
Posts: n/a
 
      12-22-2005
Hi,

in ASP.NET control events are being fired *after* the Page_Load event. I
need it the other way around. Is this possible?

Here's my example (just pseudo code):

Page_Load()
{
DataGrid.DataSource="...";
DataGrid.DataBind();
}

RemoveButton_Click()
{
SqlCommand.CommandText="DELETE ... WHERE ...";
SqlCommand.ExecuteNonQuery();
}

If I hit the RemoveButton during runtime, the DataGrid will display obsolete
data, because it is bound *before* the RemoveButton_Click() event is called.

AFAIK, performing DataGrid binding within the Page_Load event is the only
practicable way as there is no other event being called if not on PostBack.
If I have several buttons on the page, I don't see another way to put the
DataSource/DataBind pair somewhere else.

Your help is quite appreciated.

TIA,
Axel Dahmen


 
Reply With Quote
 
 
 
 
Phillip Williams
Guest
Posts: n/a
 
      12-22-2005
Within the Page_Load:
if (!Page.IsPostBack)
{
//do the databind
}

within the RemoveButton_Click add at the end the databind statements

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"Axel Dahmen" wrote:

> Hi,
>
> in ASP.NET control events are being fired *after* the Page_Load event. I
> need it the other way around. Is this possible?
>
> Here's my example (just pseudo code):
>
> Page_Load()
> {
> DataGrid.DataSource="...";
> DataGrid.DataBind();
> }
>
> RemoveButton_Click()
> {
> SqlCommand.CommandText="DELETE ... WHERE ...";
> SqlCommand.ExecuteNonQuery();
> }
>
> If I hit the RemoveButton during runtime, the DataGrid will display obsolete
> data, because it is bound *before* the RemoveButton_Click() event is called.
>
> AFAIK, performing DataGrid binding within the Page_Load event is the only
> practicable way as there is no other event being called if not on PostBack.
> If I have several buttons on the page, I don't see another way to put the
> DataSource/DataBind pair somewhere else.
>
> Your help is quite appreciated.
>
> TIA,
> Axel Dahmen
>
>
>

 
Reply With Quote
 
 
 
 
Mike MacMillan
Guest
Posts: n/a
 
      12-29-2005
Axel,
all postback events are fired right after the Page.OnLoad event by
design. since you are using the Page_Load event, this means you're
hooking into the Page.Load event. after Page.OnLoad fires, it then
fires the event on all delegates...so if doing your databinding before
Page_Load is what you need, you can override the Page.OnLoad event, do
your binding, then call base.OnLoad to pass it back to the page. there
is also the Page.OnInit event which fires before OnLoad (and
LoadViewState, etc...) which you can override/hook into for your
databinding as well.

let me know how this works,
Mike MacMillan

Axel Dahmen wrote:
> Hi,
>
> in ASP.NET control events are being fired *after* the Page_Load event. I
> need it the other way around. Is this possible?
>
> Here's my example (just pseudo code):
>
> Page_Load()
> {
> DataGrid.DataSource="...";
> DataGrid.DataBind();
> }
>
> RemoveButton_Click()
> {
> SqlCommand.CommandText="DELETE ... WHERE ...";
> SqlCommand.ExecuteNonQuery();
> }
>
> If I hit the RemoveButton during runtime, the DataGrid will display obsolete
> data, because it is bound *before* the RemoveButton_Click() event is called.
>
> AFAIK, performing DataGrid binding within the Page_Load event is the only
> practicable way as there is no other event being called if not on PostBack.
> If I have several buttons on the page, I don't see another way to put the
> DataSource/DataBind pair somewhere else.
>
> Your help is quite appreciated.
>
> TIA,
> Axel Dahmen


 
Reply With Quote
 
Axel Dahmen
Guest
Posts: n/a
 
      01-08-2006
Thanks, Phillip, for trying to help.

You are right, this is the only feasible way I know of, too, but - no
offence - I believe this is spaghetti code. There must be a structured way
of databinding and data manipulation. Without using IF and IF and IF... at
all different places.

BTW: I have this same problem with sorting a DataGrid: If !IsPostBack and
NOT one of the sorting header links is clicked, perform DataBinding in
PageLoad() - OTHERWISE perform databinding in DataGrid_SortCommand(). I even
have to address the sorting links by their HTML names!! THIS is really ugly:

PageLoad()
{
if (Request.Form["__EVENTTARGET"]==null ||
!Request.Form["__EVENTTARGET"].StartsWith("grdData:_ctl2:_ctl"))
FillDataGrid();
}

Do you perhaps see another way to perform this kind of action in a
structured manner?

Best regards and happy new Year 2006!
www.sportboatcharter.com
Axel Dahmen


-----------
"Phillip Williams" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> Within the Page_Load:
> if (!Page.IsPostBack)
> {
> //do the databind
> }
>
> within the RemoveButton_Click add at the end the databind statements
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "Axel Dahmen" wrote:
>
> > Hi,
> >
> > in ASP.NET control events are being fired *after* the Page_Load event. I
> > need it the other way around. Is this possible?
> >
> > Here's my example (just pseudo code):
> >
> > Page_Load()
> > {
> > DataGrid.DataSource="...";
> > DataGrid.DataBind();
> > }
> >
> > RemoveButton_Click()
> > {
> > SqlCommand.CommandText="DELETE ... WHERE ...";
> > SqlCommand.ExecuteNonQuery();
> > }
> >
> > If I hit the RemoveButton during runtime, the DataGrid will display

obsolete
> > data, because it is bound *before* the RemoveButton_Click() event is

called.
> >
> > AFAIK, performing DataGrid binding within the Page_Load event is the

only
> > practicable way as there is no other event being called if not on

PostBack.
> > If I have several buttons on the page, I don't see another way to put

the
> > DataSource/DataBind pair somewhere else.
> >
> > Your help is quite appreciated.
> >
> > TIA,
> > Axel Dahmen
> >
> >
> >



 
Reply With Quote
 
Axel Dahmen
Guest
Posts: n/a
 
      01-08-2006
Hi Mike,

thanks for trying to help. In fact I want to perform something different:

Let me guide you to my point: ASP.NET provides control events, BUT... they
only fire AFTER all available page event have been fired. So, AFAIK, there
is no page event available to perform some general action in a structured -
means organized - way after control events have been handled.

I'm missing a second "PageLoad()" event being fired AFTER all control events
have been fired, like:

PageInit()
PageLoad()
Control2_Click()
PageLoad2()

This would keep a programmer from using IFs and function calls at several
places, distributing logic across all page code.

I'm in the mood, so I speak right from my heart: IsPostBack is a really
ugly, unstructured feature leading to immense spaghetti code to solve
problems raised by this feature. IMHO, the IsPostBack property should
instead have been a separate event, fired right before any control event.
And the PageLoad() event should instead fire right AFTER any control event,
like:

PageInit()
PagePostBack()
Control2_Click()
PageLoad()

Another ugly solution is the way of how to implement Dispose() as suggested
by MSDN.

It seems some solutions never got beyond VB5... *sigh*

OK, enough... Do you see any structured solution to this problem? I'd
greatly appreciate that.

TIA,
www.sportboatcharter.com
Axel Dahmen



-------------
"Mike MacMillan" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed) ups.com...
> Axel,
> all postback events are fired right after the Page.OnLoad event by
> design. since you are using the Page_Load event, this means you're
> hooking into the Page.Load event. after Page.OnLoad fires, it then
> fires the event on all delegates...so if doing your databinding before
> Page_Load is what you need, you can override the Page.OnLoad event, do
> your binding, then call base.OnLoad to pass it back to the page. there
> is also the Page.OnInit event which fires before OnLoad (and
> LoadViewState, etc...) which you can override/hook into for your
> databinding as well.
>
> let me know how this works,
> Mike MacMillan
>
> Axel Dahmen wrote:
> > Hi,
> >
> > in ASP.NET control events are being fired *after* the Page_Load event. I
> > need it the other way around. Is this possible?
> >
> > Here's my example (just pseudo code):
> >
> > Page_Load()
> > {
> > DataGrid.DataSource="...";
> > DataGrid.DataBind();
> > }
> >
> > RemoveButton_Click()
> > {
> > SqlCommand.CommandText="DELETE ... WHERE ...";
> > SqlCommand.ExecuteNonQuery();
> > }
> >
> > If I hit the RemoveButton during runtime, the DataGrid will display

obsolete
> > data, because it is bound *before* the RemoveButton_Click() event is

called.
> >
> > AFAIK, performing DataGrid binding within the Page_Load event is the

only
> > practicable way as there is no other event being called if not on

PostBack.
> > If I have several buttons on the page, I don't see another way to put

the
> > DataSource/DataBind pair somewhere else.
> >
> > Your help is quite appreciated.
> >
> > TIA,
> > Axel Dahmen

>



 
Reply With Quote
 
Mike MacMillan
Guest
Posts: n/a
 
      01-09-2006
Axel,
per the execution lifecycle, you have the PreRender event which you
can use, that gets fired right after Load...ex:
Init
Load
PreRender

is there any reason you need your logic bound to the Load event, or
will using the PreRender event suffice? perhaps you can explain a
little more in detail why you've chosen this specific architecture, and
we can come up with a workaround/solution.

Mike MacMillan



Axel Dahmen wrote:
> Hi Mike,
>
> thanks for trying to help. In fact I want to perform something different:
>
> Let me guide you to my point: ASP.NET provides control events, BUT... they
> only fire AFTER all available page event have been fired. So, AFAIK, there
> is no page event available to perform some general action in a structured -
> means organized - way after control events have been handled.
>
> I'm missing a second "PageLoad()" event being fired AFTER all control events
> have been fired, like:
>
> PageInit()
> PageLoad()
> Control2_Click()
> PageLoad2()
>
> This would keep a programmer from using IFs and function calls at several
> places, distributing logic across all page code.
>
> I'm in the mood, so I speak right from my heart: IsPostBack is a really
> ugly, unstructured feature leading to immense spaghetti code to solve
> problems raised by this feature. IMHO, the IsPostBack property should
> instead have been a separate event, fired right before any control event.
> And the PageLoad() event should instead fire right AFTER any control event,
> like:
>
> PageInit()
> PagePostBack()
> Control2_Click()
> PageLoad()
>
> Another ugly solution is the way of how to implement Dispose() as suggested
> by MSDN.
>
> It seems some solutions never got beyond VB5... *sigh*
>
> OK, enough... Do you see any structured solution to this problem? I'd
> greatly appreciate that.
>
> TIA,
> www.sportboatcharter.com
> Axel Dahmen
>
>
>
> -------------
> "Mike MacMillan" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:(E-Mail Removed) ups.com...
> > Axel,
> > all postback events are fired right after the Page.OnLoad event by
> > design. since you are using the Page_Load event, this means you're
> > hooking into the Page.Load event. after Page.OnLoad fires, it then
> > fires the event on all delegates...so if doing your databinding before
> > Page_Load is what you need, you can override the Page.OnLoad event, do
> > your binding, then call base.OnLoad to pass it back to the page. there
> > is also the Page.OnInit event which fires before OnLoad (and
> > LoadViewState, etc...) which you can override/hook into for your
> > databinding as well.
> >
> > let me know how this works,
> > Mike MacMillan
> >
> > Axel Dahmen wrote:
> > > Hi,
> > >
> > > in ASP.NET control events are being fired *after* the Page_Load event. I
> > > need it the other way around. Is this possible?
> > >
> > > Here's my example (just pseudo code):
> > >
> > > Page_Load()
> > > {
> > > DataGrid.DataSource="...";
> > > DataGrid.DataBind();
> > > }
> > >
> > > RemoveButton_Click()
> > > {
> > > SqlCommand.CommandText="DELETE ... WHERE ...";
> > > SqlCommand.ExecuteNonQuery();
> > > }
> > >
> > > If I hit the RemoveButton during runtime, the DataGrid will display

> obsolete
> > > data, because it is bound *before* the RemoveButton_Click() event is

> called.
> > >
> > > AFAIK, performing DataGrid binding within the Page_Load event is the

> only
> > > practicable way as there is no other event being called if not on

> PostBack.
> > > If I have several buttons on the page, I don't see another way to put

> the
> > > DataSource/DataBind pair somewhere else.
> > >
> > > Your help is quite appreciated.
> > >
> > > TIA,
> > > Axel Dahmen

> >


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to iterate over sequence and non-sequence ? stef mientki Python 13 10-20-2007 10:21 AM
question about event sequence for Page_Load and Menu1_MenuItemClic =?Utf-8?B?SmF5?= ASP .Net 3 12-21-2005 07:07 PM
Event Sequence Wrong Josh ASP .Net 1 08-17-2005 11:22 AM
PostBack Event Firing Sequence Guadala Harry ASP .Net 3 08-15-2004 07:42 AM
BOOT SEQUENCE (how to change boot sequence) bird Computer Support 13 12-24-2003 02:20 AM



Advertisments