Thanks, Ken, for the tips.
Scott Allen solved my problem (factor out code, call it from all postback
handlers, in addition to load handler if IsPostBack is false).
But you're right, taking advantage of ASP.NET custom controls and
client-side script event postbacks (e.g. the Page classes methods) is another
long-term solution to it.
Homam
"Ken Dopierala Jr." wrote:
[color=blue]
> Hi Homam,
>
> I don't see how firing a js function to set a flag that notifies the server
> that the criteria has changed causes any problems. Especially once you
> encapsulate this functionality into a custom control and simply drop it on
> any page you need it. As you know the page load event will always fire
> before the button click. Without using any type of smart-client
> functionality all your work needs to be done on the server. The only way to
> do this is to maintain state. You can do that with the Session object. In
> your page load, compare the new criteria to the old criteria. If it doesn't
> match then you know what you need to do. However once your pages become
> more complicated, specifically post backs can be made from actions other
> than the submit button click, you may find that simply having the client
> tell you what they need instead of making the server figure it out, is the
> way to go. Good luck! I hope more people can join this conversation and
> help put together the right solution for you. Ken.
>
> --
> Ken Dopierala Jr.
> For great ASP.Net web hosting try:
>
http://www.webhost4life.com/default.asp?refid=Spinlight
> If you sign up under me and need help, email me.
>
> "Homam" <Homam@discussions.microsoft.com> wrote in message
> news:05F9E38A-31BB-4CB4-BD93-0E08AD5E30EA@microsoft.com...[color=green]
> > Hi Ken,
> >
> > Using JavaScript and hidden form fields is pretty much the same hack as
> > checking whether the SubmitButton exists in the form object. I'm just[/color]
> trying[color=green]
> > to figure out a solution along the line of ASP.NET's event-driven, OO[/color]
> model.[color=green]
> >
> > Thanks,
> >
> > Homam
> >
> >
> >
> >
> > "Ken Dopierala Jr." wrote:
> >[color=darkred]
> > > Hi,
> > >
> > > I think implementing a Master Pages type scenario is what you are[/color][/color]
> looking[color=green][color=darkred]
> > > for. They are built into v2.0 of the framework but here are some link[/color][/color]
> for[color=green][color=darkred]
> > > implementing them in v1.1:
> > >
> > >
http://www.codeproject.com/aspnet/PageFramework.asp
> > >
> > >
http://www.codeproject.com/aspnet/Frame_Work_Design.asp
> > >
> > > Also read through this from Microsoft's Patterns & Practices:
> > >
> > >[/color][/color]
>
http://msdn.microsoft.com/library/de...tml/DesMVC.asp[color=green][color=darkred]
> > >
> > > For your paging navigation I would recommend creating your own custom
> > > control with all UI necessary to page (i.e. page selection links or
> > > dropdown, submit button, previous/next links). This will allow you to[/color][/color]
> make[color=green][color=darkred]
> > > it very generic and at the same time expose a number of custom[/color][/color]
> properties[color=green][color=darkred]
> > > that can be changed in the property window of the IDE to customize for[/color][/color]
> any[color=green][color=darkred]
> > > scenario. For example in one scenario you may show the current page and
> > > links to the two pages behind or ahead of it. Where as in another[/color][/color]
> scenario[color=green][color=darkred]
> > > you may show the page you are on, the immediate pages around it and[/color][/color]
> links to[color=green][color=darkred]
> > > also go all the way to the beginning or end of the data. In your custom
> > > control include the javascript necessary to set a hidden input to the
> > > correct page when the submit button is clicked. Then have your base[/color][/color]
> page[color=green][color=darkred]
> > > check this hidden input before loading the data. Now you'll know where[/color][/color]
> to[color=green][color=darkred]
> > > go before the submit button click even fires. In fact, you wouldn't[/color][/color]
> even[color=green][color=darkred]
> > > need to capture the click event on the server-side. Good luck! Ken.
> > >
> > > --
> > > Ken Dopierala Jr.
> > > For great ASP.Net web hosting try:
> > >
http://www.webhost4life.com/default.asp?refid=Spinlight
> > > If you sign up under me and need help, email me.
> > >
> > > "Homam" <Homam@discussions.microsoft.com> wrote in message
> > > news:C138BFAD-0487-42A5-B762-A91F16E76DA8@microsoft.com...
> > > > Hi Ken,
> > > >
> > > > This wouldn't slove my problem because even when I add an intermediate
> > > > class, the overloaded Load event will still fire before the[/color][/color]
> SubmitButton's[color=green][color=darkred]
> > > > Click event. So if the user clicked on that button to update the[/color][/color]
> criteria,[color=green][color=darkred]
> > > > the current page will be set AFTER the query has already executed, and[/color][/color]
> the[color=green][color=darkred]
> > > > ResultSetDisplay will display the wrong page.
> > > >
> > > > To illustrate, let's say that the user submitted a set of criteria C1[/color][/color]
> and[color=green][color=darkred]
> > > > browsed to page number 5 of the its result set. Then he changed the
> > > criteria
> > > > to C2 and hit the SubmitButton. Now if I execute the query in the
> > > overloaded
> > > > Load event handler in the derived class, the query will retrieve page[/color][/color]
> 5 of[color=green][color=darkred]
> > > > C2, not page 1 as it should, because the page was set in the[/color][/color]
> SubmitButton[color=green][color=darkred]
> > > > event handler after the query got executed.
> > > >
> > > > By the way, the code is executed in the Code Behind class, which is
> > > derived
> > > > from Page anyway.
> > > >
> > > > I'm very well versed in OOA/D/P and all the design patterns[/color][/color]
> paraphernalia[color=green][color=darkred]
> > > (I
> > > > come from a J2EE background), but I'm still trying to figure out[/color][/color]
> ASP.NET's[color=green][color=darkred]
> > > > plumbing.
> > > >
> > > > Thanks for your feedback.
> > > >
> > > >
> > > >
> > > >
> > > > "Ken Dopierala Jr." wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > I would create a base page class and derive my pages from this[/color][/color]
> class.[color=green][color=darkred]
> > > The
> > > > > base page's Page_Load event will fire first, you can then hit your[/color][/color]
> data[color=green][color=darkred]
> > > > > access and business logic layers here. Retrieving the data you need[/color][/color]
> and[color=green][color=darkred]
> > > > > setting custom properties for derived classes to check before they
> > > render.
> > > > >
> > > > > I would also recommend buying some books on OOP and studying them
> > > carefully.
> > > > > You attempted to solve your problem using an almost top-down[/color][/color]
> approach.[color=green][color=darkred]
> > > When
> > > > > you are trying to implement an OO design you know you are on the[/color][/color]
> wrong[color=green][color=darkred]
> > > path
> > > > > when you try to rig things up after the fact. Always try to think[/color][/color]
> what[color=green][color=darkred]
> > > > > would come first. In this case a base class will solve your problem[/color][/color]
> and[color=green][color=darkred]
> > > > > also make your code much more elegant and extensible. Good luck![/color][/color]
> Ken.[color=green][color=darkred]
> > > > >
> > > > > --
> > > > > Ken Dopierala Jr.
> > > > > For great ASP.Net web hosting try:
> > > > >
http://www.webhost4life.com/default.asp?refid=Spinlight
> > > > > If you sign up under me and need help, email me.
> > > > >
> > > > > "Homam" <Homam@discussions.microsoft.com> wrote in message
> > > > > news:A2C2B1CE-90B5-4D49-9FCF-0D9B8733CDC0@microsoft.com...
> > > > > > The ASP.NET model is touted as a clean OO approach to developing[/color][/color]
> web[color=green][color=darkred]
> > > > > pages,
> > > > > > yet sometimes the page lifecycle poses silly obstacles that forces[/color][/color]
> you[color=green][color=darkred]
> > > > > revert
> > > > > > to the Olde ASP 3.0 Ways.
> > > > > >
> > > > > > Here's a rough outline of an ASPX page:
> > > > > >
> > > > > > ... a bunch of criteria controls...
> > > > > > PagingNav
> > > > > > ResultSetDisplay
> > > > > > SubmitButton
> > > > > >
> > > > > > Basically, the PagingNav allows the user to navigate through the[/color][/color]
> DB[color=green][color=darkred]
> > > result
> > > > > > set; the ResultSetDisplay shows the currently selected page in a[/color][/color]
> data[color=green][color=darkred]
> > > > > list;
> > > > > > and the SubmitButton is used in case the user changed criteria and
> > > wants
> > > > > to
> > > > > > update the view.
> > > > > >
> > > > > > Now, the PagingNav control needs to know the total number of[/color][/color]
> records[color=green][color=darkred]
> > > found
> > > > > > in the DB, so the query must be exectued before it's rendered.
> > > Therefore I
> > > > > > have to execute the query before the PreRender event of PagingNav,
> > > which
> > > > > > means I cannot, for example, execute the query in the PreRender[/color][/color]
> event[color=green][color=darkred]
> > > of
> > > > > the
> > > > > > ResultSetDisplay control since it will be executed after the[/color][/color]
> PreRender[color=green][color=darkred]
> > > > > event
> > > > > > of the PagingNav control (due to its position in the page). In[/color][/color]
> other[color=green][color=darkred]
> > > > > words,
> > > > > > it would be too late for the PageNavControl to figure out the[/color][/color]
> total[color=green][color=darkred]
> > > > > records
> > > > > > the query found. I can execute the query in any event of
> > > ResultSetDisplay
> > > > > > that fires before PreRender. So far so good.
> > > > > >
> > > > > > Enter the SubmitButton control, which messes up the whole plan.[/color][/color]
> The[color=green][color=darkred]
> > > > > problem
> > > > > > is, I want to reset the current page number to 1 whenever this[/color][/color]
> button[color=green][color=darkred]
> > > is
> > > > > > clicked. So I add code to do that in its SubmitButton_Click. Alas,
> > > this
> > > > > event
> > > > > > executes AFTER the Load event of the ResultSetDisplay and BEFORE[/color][/color]
> its[color=green][color=darkred]
> > > > > > PreRender event. This means to get the ResultSetDisplay to dispay[/color][/color]
> the[color=green][color=darkred]
> > > > > > appropriate page (i.e. # 1), I have to excute the query in an[/color][/color]
> event[color=green][color=darkred]
> > > that
> > > > > > takes place after the SubmitButton_Click event, which is the[/color][/color]
> PreRender[color=green][color=darkred]
> > > > > event.
> > > > > > But that pretty much screws up the PagingNav control since, as
> > > explained
> > > > > > above, it needs to find out how many records the query found, but[/color][/color]
> it's[color=green][color=darkred]
> > > too
> > > > > > late now.
> > > > > >
> > > > > > So, to fix the problem, I have to revert to ASP 3.0 hacks and add
> > > > > something
> > > > > > in the Load event of the ResultSetDispay such as:
> > > > > >
> > > > > > if (Request.Form["update"] != null)
> > > > > > this.currentPage = 1;
> > > > > >
> > > > > > which is totally against the OO style of ASP.NET.
> > > > > >
> > > > > > So my question is, how would you guys solve such a problem neatly?
> > > > > >
> > > > >
> > > > >
> > > > >
> > >
> > >
> > >[/color][/color]
>
>
>[/color]