|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Event Sequencein 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 Within the Page_Load:
if (!Page.IsPostBack) { //do the databind } within the RemoveButton_Click add at the end the databind statements Show quoteHide quote "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 > > > 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 ----------- Show quoteHide quote "Phillip Williams" <Phillip.Willi***@webswapp.com> schrieb im Newsbeitrag news:8F94E832-08B6-4561-A111-27F4ABA34350@microsoft.com... > 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 > > > > > > 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: Show quoteHide quote > 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 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 ------------- Show quoteHide quote "Mike MacMillan" <mikejmacmil***@gmail.com> schrieb im Newsbeitrag news:1135814813.120938.81340@g49g2000cwa.googlegroups.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 > 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: Show quoteHide quote > 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" <mikejmacmil***@gmail.com> schrieb im Newsbeitrag > news:1135814813.120938.81340@g49g2000cwa.googlegroups.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 > >
ReportViewer/ObjectDataSource Problem
objectdatasource.update() fires System.InvalidOperationException THEAD DropDownList not giving the selected item when a Button is clicked... please help newbie... Hide SideBar of Wizard Control How to determine the "state" of a GridView Web Control Positioning Better tool for selection - Datagrid or DataList? Quick/Embarrasing Form Submission Question Required field validator |
|||||||||||||||||||||||