473,394 Members | 1,785 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,394 software developers and data experts.

ASP.NET Design Suggestions

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

Jan 21 '08 #1
8 935
"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:OY**************@TK2MSFTNGP05.phx.gbl...
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

Jan 21 '08 #2
Okay, yeah, I guess that makes sense.

Thanks.

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

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:OY**************@TK2MSFTNGP05.phx.gbl...
>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
Jan 21 '08 #3
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:
Jan 21 '08 #4
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" <jw***@softcircuits.comwrote in message
news:OY**************@TK2MSFTNGP05.phx.gbl...
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

Jan 21 '08 #5
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:%2****************@TK2MSFTNGP03.phx.gbl...
>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

Jan 21 '08 #6
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)" <No************@comcast.netNoSpamMwrote in
message news:%2****************@TK2MSFTNGP03.phx.gbl...
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

Jan 21 '08 #7
Indeed. I find the insinuation that "spaghetti code" is "bad" to be
religiously offensive.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.NoSpamMaam.comwrote in message
news:E4**********************************@microsof t.com...
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)" <No************@comcast.netNoSpamMwrote in
message news:%2****************@TK2MSFTNGP03.phx.gbl...
>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

Jan 21 '08 #8
"Peter Bromberg [C# MVP]" <pb*******@yahoo.NoSpamMaam.comwrote in message
news:E4**********************************@microsof t.com...
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

Jan 21 '08 #9

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

Similar topics

7
by: Pelle Beckman | last post by:
Hi, I've just finished writing a template (whew!) and would like some opinions on the design. The goal was to be able to do fairly simple singletons (no excplicit thread-safety, etc) and...
2
by: Mike | last post by:
Hi I have been tasked with converting my pulp and paper mills weekly projected and actual contractor hrs excel spreadsheet into a an Access 97 database. So far my design has been to use a...
7
by: Susan Bricker | last post by:
Greetings. As a relative newcomer to Access, I am having trouble deciding on how to design the form flow for updating and creating related records. I'm looking for a variety of suggestions so...
6
by: Orgun | last post by:
Hi, I sent this message to the moderated c++ group too but it is waiting for moderator approval and I wanted to send here too. I am new to Design Patterns. I want to write a simple...
4
by: alacrite | last post by:
I have a class that I want to turn its contents into csv file. I want to be able to set the value of the delimiter, the name of the file it gets saved to, the path of that file, and maybe a few...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
5
by: rdemyan via AccessMonster.com | last post by:
I have a need to add another field to all of my tables (over 150). Not data, but an actual field. Can I code this somehow. So the code presumabley would loop through all the tables, open each...
2
by: Jami Bradley | last post by:
I'm in need of some design suggestions! We have a fairly large DB with thousands of users accessing data throughout the day. I have been given the task of restructuring a core part of the web...
0
by: krzysztof.konopko | last post by:
I know that the informations I provide may seem limited but maybe someone has solved similar problem. I am new in design patterns and I am quite confused who should control whom, how to configure...
4
by: Ken Fine | last post by:
I've been living with a frustrating issue with VS.NET for some months now and I need to figure out what the problem is. Hopefully someone has run into the same issue and can suggest a fix. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.