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

A better workaround?


A framework issue rather than a pure C# issue, so a little off topic,
but the aspnet.webcontrols group is very quiet, and people here seem
more experienced:

I came across an irritating problem with the ASP.NET execution model
about which I've seen several people ask questions but have seen few
good answers.

The exact details are not really important, but to give you an idea, I
need to provide a set of arbitrary page designs associated with
particular combinations of entries in a directory structure. As the user
browses the directory structure (various ways of slicing a market sector
segmentation model) they will be presented with pages which either show
a default web page or else specific content. The layout and content is
user-configurable and is stored in the database and retrieved with the
home page object.

There's a directory browser control which manages the navigation and
maintains some session state (basically encapsulates an object
containing a hashtable of available dimension lists and a stack of
selected ones). It raises an event when the current directory path
changes, passing a specification object which is picked up by the page.
The page then uses that to obtain a MarketSectorHomePage.

The MarketSectorHomePage is exposed by the page via an interface, and is
displayed by a home page control. So we have:

public class ViewMSHP : System.Web.UI.Page,
IMarketSectorHomePageHost{...}

where IMarketSectorHomePageHost is defined as:

public interface IMarketSectorHomePageHost
{
MarketSectorHomePage MarketSectorHomePage
{
get;
set;
}
}

The base class of the home page control (BaseMarketSectorControl)
accesses the interface in the page like so:

IMarketSectorHomePageHost host = this.Page as IMarketSectorHomePageHost;

and exposes the MarketSectorHomePage to derived classes through a
protected property.

In CreateChildControls the home page control then examines the
MarketSectorHomePage object's PageContents object which defines the
names of the controls and their row and column positions. It creates a
table, inserting table cells and populating them with custom controls
created by reflection from the names defined in page contents. The
controls may or may not themselves be derived from
BaseMarketSectorControl, depending on whether they need to access and
render information from the MarketSectorHomePage.

This model works nicely when the MarketSectorHomePage is not changing
between postbacks, however when used in the above scenario where a
postback is induced by the directory browser it falls over. The control
tree created by the homepage control is not the same one as present on
the previous call, ASPNET can't find the controls where it thinks they
should be, and blows up.

It occurs to me that the same sort of thing would happen in many
scenarios with a classic model-view-controller architecture (and this
is, if you squint, MVC-like with looser than usual coupling).

After much messing about, I found a neat but unsatisfying workaround;
insert two instances of the home page control at the same location in
the page. Set the visible property of one to true, the other to false.
In OnPreRender, toggle the Visible property. Thus neither control is
visible both before and after a postback. If it isn't visible, it isn't
rendered, CreateChildControls doesn't run, everything works.

It works, but I wonder whether anyone has found a better way of dealing
with it?

--
Steve Walker
Nov 17 '05 #1
0 886

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

Similar topics

2
by: HI-Lab * the Social Technology | last post by:
Is there another function or a workaround to have same results of html_entity_decode in php 4.1.x? Thanks. -- ======================================= HI-LAB the Social Technology...
6
by: Chris | last post by:
hi, to convert excel files via csv to xml or whatever I frequently use the csv module which is really nice for quick scripts. problem are of course non ascii characters like german umlauts, EURO...
100
by: Peter | last post by:
Company thought DB2 will be better than Oracle. The bottom line is when you do select, the system crash. I think it may take 4-5 years for DB2 to reach Oracle standard. Peter
16
by: Bhushit Joshipura | last post by:
This post contains one question and one proposal. A. May I know why order of evaluation of arguments is not specified in C/C++? I asked a question in comp.lang.c++ for the following...
1
by: Ronaldo N | last post by:
I'm trying to do some javascript form validation and I've discovered a rather difficult situation to handle with IE. Let's say there's a form with three input fields named "name", "method", or...
7
by: Justin Shen | last post by:
the output of the following codes is "greater than zero", which is rather strange! the correct one should be "not greater than zero" int a = 0x79de61c0; //2044617152; a += 0x12345678; //a is...
9
by: Mickey Segal | last post by:
The long-simmering Eolas patent dispute: http://www.microsoft.com/presspass/press/2003/oct03/10-06EOLASPR.mspx has led to an optional Microsoft Update: http://support.microsoft.com/kb/912945/en-us...
1
by: slyi | last post by:
Hi All, Does anyone use vml to force the printing of background-colors in IE clients? Regards, slyi eg: <html xmlns:v="urn:schemas-microsoft-com:vml" >
0
by: William Johnston | last post by:
Hi, A support technician proposed a workaround to black images created for thumbnails. The code to create a thumbnail is below: //passes results to Response.OutputStream private void...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.