PC Review


Reply
Thread Tools Rate Thread

ASP.NET Design Suggestions

 
 
Jonathan Wood
Guest
Posts: n/a
 
      21st Jan 2008
I'm trying to get a good understanding of this.

I have a page that is fairly complex and makes a number of database
accesses. I'd love to cache it but, since the data will be specific to the
user's current settings, that doesn't really seem to be a useful option.

I also have a button that should change some data and then refresh the page.

The problems are:

1) The entire page rebuilds in the load event before the button handler is
called. I know I can test IsPostBack, but when the data changes, I really
need to rebuild the entire page.

2) Since the page has already been build when the button handler is called,
changing the data has no effect.

It almost seems like it would be better if the button handler was called
first. At any rate, I'm just wondering if some of you have dealt much with
this quirk and how best to deal with it.

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      21st Jan 2008
"Jonathan Wood" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> It almost seems like it would be better if the button handler was called
> first. At any rate, I'm just wondering if some of you have dealt much with
> this quirk and how best to deal with it.


Page_Load(...)
{
if (!IsPostBack)
{
BindData();
}
}

ButtonClick(...)
{
BindData();
}

void BindData()
{
// fetch the data...
}


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Jonathan Wood
Guest
Posts: n/a
 
      21st Jan 2008
Okay, yeah, I guess that makes sense.

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Mark Rae [MVP]" <(E-Mail Removed)> wrote in message
news:%23sc%(E-Mail Removed)...
> "Jonathan Wood" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> It almost seems like it would be better if the button handler was called
>> first. At any rate, I'm just wondering if some of you have dealt much
>> with this quirk and how best to deal with it.

>
> Page_Load(...)
> {
> if (!IsPostBack)
> {
> BindData();
> }
> }
>
> ButtonClick(...)
> {
> BindData();
> }
>
> void BindData()
> {
> // fetch the data...
> }
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net


 
Reply With Quote
 
Michael Nemtsev
Guest
Posts: n/a
 
      21st Jan 2008
> I have a page that is fairly complex and makes a number of database
> accesses. I'd love to cache it but, since the data will be specific to the
> user's current settings, that doesn't really seem to be a useful option.


It depends. And actualy it's posible. What I've done is use asp.net
profiling data and buld "Data Bus" which interacted with that data.

You can find some of my thoughs about this there
http://laflour.spaces.live.com/blog/cns!7575E2FFC19135B4!662.entry?&_c02_owner=1

--
WBR, Michael Nemtsev [.NET/C# MVP].
Blog: http://spaces.live.com/laflour



"Jonathan Wood" wrote:


 
Reply With Quote
 
Cowboy \(Gregory A. Beamer\)
Guest
Posts: n/a
 
      21st Jan 2008
I wanted to add something to Mark's post.

First, there is rarely a time when you use IsPostBack. !IsPostBack is
common, as you are first painting the page, but IsPostBack only leads you to
problems. You end up with something like this:

if(!IsPostBack)
{
//Code to paint page initially
}
else
{
if (button1.Click)
{}
else if (button2.Click)
{}
else
{}
}

You then find you are in spaghetti land.

Second, you have evens for each button. Use them.

Third, it is a good practice to separate function, in properly named
routines, from event handlers and methods. Not only does it make intent
clear, but it has an extra bonus if you ever have to obfuscate: None of your
code is easily accessible to those attempting to reverse engineer.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
"Jonathan Wood" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm trying to get a good understanding of this.
>
> I have a page that is fairly complex and makes a number of database
> accesses. I'd love to cache it but, since the data will be specific to the
> user's current settings, that doesn't really seem to be a useful option.
>
> I also have a button that should change some data and then refresh the
> page.
>
> The problems are:
>
> 1) The entire page rebuilds in the load event before the button handler is
> called. I know I can test IsPostBack, but when the data changes, I really
> need to rebuild the entire page.
>
> 2) Since the page has already been build when the button handler is
> called, changing the data has no effect.
>
> It almost seems like it would be better if the button handler was called
> first. At any rate, I'm just wondering if some of you have dealt much with
> this quirk and how best to deal with it.
>
> Thanks.
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>



 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      21st Jan 2008
"Cowboy (Gregory A. Beamer)" <(E-Mail Removed)> wrote in
message news:%(E-Mail Removed)...

>I wanted to add something to Mark's post.
>
> First, there is rarely a time when you use IsPostBack. !IsPostBack is
> common, as you are first painting the page, but IsPostBack only leads you
> to problems. You end up with something like this:
>
> if(!IsPostBack)
> {
> //Code to paint page initially
> }
> else
> {
> if (button1.Click)
> {}
> else if (button2.Click)
> {}
> else
> {}
> }
>
> You then find you are in spaghetti land.


I completely disagree with the above... The "else" clause that you suggest
just doesn't happen. There's no way in the world that anyone would do what
you suggest. If Button2 has caused the postback, then its Click (or
whatever) event will fire - there's absolutely no need at all to go through
any of the above logic to check whether Button1, or any other control, has
caused the postback...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Peter Bromberg [C# MVP]
Guest
Posts: n/a
 
      21st Jan 2008
Thanks for chasing away the Pastafarians.
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com


"Mark Rae [MVP]" wrote:

> "Cowboy (Gregory A. Beamer)" <(E-Mail Removed)> wrote in
> message news:%(E-Mail Removed)...
>
> >I wanted to add something to Mark's post.
> >
> > First, there is rarely a time when you use IsPostBack. !IsPostBack is
> > common, as you are first painting the page, but IsPostBack only leads you
> > to problems. You end up with something like this:
> >
> > if(!IsPostBack)
> > {
> > //Code to paint page initially
> > }
> > else
> > {
> > if (button1.Click)
> > {}
> > else if (button2.Click)
> > {}
> > else
> > {}
> > }
> >
> > You then find you are in spaghetti land.

>
> I completely disagree with the above... The "else" clause that you suggest
> just doesn't happen. There's no way in the world that anyone would do what
> you suggest. If Button2 has caused the postback, then its Click (or
> whatever) event will fire - there's absolutely no need at all to go through
> any of the above logic to check whether Button1, or any other control, has
> caused the postback...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net
>
>

 
Reply With Quote
 
Scott Roberts
Guest
Posts: n/a
 
      21st Jan 2008
Indeed. I find the insinuation that "spaghetti code" is "bad" to be
religiously offensive.


"Peter Bromberg [C# MVP]" <(E-Mail Removed)> wrote in message
news:E4E74991-092F-480F-A8C4-(E-Mail Removed)...
> Thanks for chasing away the Pastafarians.
> --
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> MetaFinder: http://www.blogmetafinder.com
>
>
> "Mark Rae [MVP]" wrote:
>
>> "Cowboy (Gregory A. Beamer)" <(E-Mail Removed)> wrote in
>> message news:%(E-Mail Removed)...
>>
>> >I wanted to add something to Mark's post.
>> >
>> > First, there is rarely a time when you use IsPostBack. !IsPostBack is
>> > common, as you are first painting the page, but IsPostBack only leads
>> > you
>> > to problems. You end up with something like this:
>> >
>> > if(!IsPostBack)
>> > {
>> > //Code to paint page initially
>> > }
>> > else
>> > {
>> > if (button1.Click)
>> > {}
>> > else if (button2.Click)
>> > {}
>> > else
>> > {}
>> > }
>> >
>> > You then find you are in spaghetti land.

>>
>> I completely disagree with the above... The "else" clause that you
>> suggest
>> just doesn't happen. There's no way in the world that anyone would do
>> what
>> you suggest. If Button2 has caused the postback, then its Click (or
>> whatever) event will fire - there's absolutely no need at all to go
>> through
>> any of the above logic to check whether Button1, or any other control,
>> has
>> caused the postback...
>>
>>
>> --
>> Mark Rae
>> ASP.NET MVP
>> http://www.markrae.net
>>
>>


 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      21st Jan 2008
"Peter Bromberg [C# MVP]" <(E-Mail Removed)> wrote in message
news:E4E74991-092F-480F-A8C4-(E-Mail Removed)...

> Thanks for chasing away the Pastafarians.


It all becomes clear once you get pasta certain point...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Design suggestions NNlogistics Microsoft Access Getting Started 7 9th Oct 2009 06:20 PM
Need design suggestions jtriggs1941 Microsoft Access Database Table Design 4 2nd Apr 2008 12:45 AM
Looking for Design Suggestions Jonathan Wood Microsoft ADO .NET 6 1st Feb 2008 03:35 AM
New DMZ design suggestions... shawn Microsoft Windows 2000 Active Directory 4 6th Jul 2006 05:29 PM
Design Suggestions?? =?Utf-8?B?QnJvb2s=?= Microsoft Access Forms 6 25th Apr 2005 03:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:30 AM.