Pattern/ help wanted for Request

G

Guest

Hello.

In the good ol'ASP-days I allways handled all request vars within a class. I
want to do the same in ASP.NET. It can be done smart and maybe not so smart -
and I need help for the first part :)

I've the following:
public class UserSettings
{

System.Web.UI.Page _page;

public UserSettings(System.Web.UI.Page page)
{
this._page = page;
}
public DateTime Calendar1SelectedDate()
{
? this._page.FindControl("Calendar1");

}
}

But as you can see I allready stumpled across the calendarcontrol :-(
Can anybody put me in the right direction or maybe come up with a better
solution, maybe a designpattern?

Kind regards
 
G

Guest

I'm not all that familiar with the programming model of the good ol' ASP
days; but the bright new future with ASP.NET follows the Windows Forms design
model. Objects on the webpage correspond to objects in your code behind.
Prior to your code running, the viewstate of all the controls are
deserialized and the control objects are re-constructed for the postback
event. In your code, you would do something similar to this:

protected void Page_Load(object sender, EventArgs e)
{
UserSettings settings = this.Session["UserSettings"] as UserSettings;
if(settings == null)
{
settings = new UserSettings();
this.Session["UserSettings"] = settings;
}
settings.DOB = this.dateOfBirthCalendar.SelectedDate; // pseudo code
here, sorry
}
 
G

Guest

Hello William, thank you for your quick response.

Unfortunately that's not what im looking for. The solution you proposed are
allready breaking a couple of things in my world....
An object into a session - not recommended. Well anyway, I would like a
more, "seen from an arcithectural point of view" - designpattern :) I've to
know a lot about the controls in the "normal" way, and it should be more
anonymous....

Any suggestions?

It could turn out that im trying to kill small birds with a gatlingun,
but.... :)
Kind regards

William Sullivan said:
I'm not all that familiar with the programming model of the good ol' ASP
days; but the bright new future with ASP.NET follows the Windows Forms design
model. Objects on the webpage correspond to objects in your code behind.
Prior to your code running, the viewstate of all the controls are
deserialized and the control objects are re-constructed for the postback
event. In your code, you would do something similar to this:

protected void Page_Load(object sender, EventArgs e)
{
UserSettings settings = this.Session["UserSettings"] as UserSettings;
if(settings == null)
{
settings = new UserSettings();
this.Session["UserSettings"] = settings;
}
settings.DOB = this.dateOfBirthCalendar.SelectedDate; // pseudo code
here, sorry
}


Bobstar said:
Hello.

In the good ol'ASP-days I allways handled all request vars within a class. I
want to do the same in ASP.NET. It can be done smart and maybe not so smart -
and I need help for the first part :)

I've the following:
public class UserSettings
{

System.Web.UI.Page _page;

public UserSettings(System.Web.UI.Page page)
{
this._page = page;
}
public DateTime Calendar1SelectedDate()
{
? this._page.FindControl("Calendar1");

}
}

But as you can see I allready stumpled across the calendarcontrol :-(
Can anybody put me in the right direction or maybe come up with a better
solution, maybe a designpattern?

Kind regards
 
R

Ray Booysen

Hi Bobstar

Why is putting an object into session a bad idea?
What is this "normal" way you know about controls?
And what do you mean by doing things in a more anonymous way?
Hello William, thank you for your quick response.

Unfortunately that's not what im looking for. The solution you proposed are
allready breaking a couple of things in my world....
An object into a session - not recommended. Well anyway, I would like a
more, "seen from an arcithectural point of view" - designpattern :) I've to
know a lot about the controls in the "normal" way, and it should be more
anonymous....

Any suggestions?

It could turn out that im trying to kill small birds with a gatlingun,
but.... :)
Kind regards

William Sullivan said:
I'm not all that familiar with the programming model of the good ol' ASP
days; but the bright new future with ASP.NET follows the Windows Forms design
model. Objects on the webpage correspond to objects in your code behind.
Prior to your code running, the viewstate of all the controls are
deserialized and the control objects are re-constructed for the postback
event. In your code, you would do something similar to this:

protected void Page_Load(object sender, EventArgs e)
{
UserSettings settings = this.Session["UserSettings"] as UserSettings;
if(settings == null)
{
settings = new UserSettings();
this.Session["UserSettings"] = settings;
}
settings.DOB = this.dateOfBirthCalendar.SelectedDate; // pseudo code
here, sorry
}


Bobstar said:
Hello.

In the good ol'ASP-days I allways handled all request vars within a class. I
want to do the same in ASP.NET. It can be done smart and maybe not so smart -
and I need help for the first part :)

I've the following:
public class UserSettings
{

System.Web.UI.Page _page;

public UserSettings(System.Web.UI.Page page)
{
this._page = page;
}
public DateTime Calendar1SelectedDate()
{
? this._page.FindControl("Calendar1");

}
}

But as you can see I allready stumpled across the calendarcontrol :-(
Can anybody put me in the right direction or maybe come up with a better
solution, maybe a designpattern?

Kind regards
 
G

Guest

Nope, I don't have any suggestions to do it the way you want. ASP.NET is
pretty rigid in its design model. I know you are used to doing things in
your particular manner; you might want to stick with your ASP model rather
than trying to shoe-horn it into ASP.NET. To do it your way, you'd have to
design a middle tier analogous to a data-adapter to stand inbetween the web
form's controls and your settings objects. Is it worth it? I wouldn't think
so, unless you are attempting to design the system to work with any web
application, thus making anonymity a design requirement. For a single web
app, I'd definitely call that approach "gatling gun vs. mosquito."

And on the Session holding user data... It is one of the core components in
ASP.NET, along with its user-common data store, the Cache. The main
complaint I have with it (it functions extremely well in all other cases) is
that out-of-proc session state servers (such as dedicated machines and Sql
Server databases) lack some of the functionality of the inproc session state.
Also, the session state bag is not type safe, but I avoid this by using a
session adapter that stores generic collections of objects I wish to
associate with the user's session (an approach that can reach gatling
proportions if you go crazy with it).

Good luck with your approach.

Bobstar said:
Hello William, thank you for your quick response.

Unfortunately that's not what im looking for. The solution you proposed are
allready breaking a couple of things in my world....
An object into a session - not recommended. Well anyway, I would like a
more, "seen from an arcithectural point of view" - designpattern :) I've to
know a lot about the controls in the "normal" way, and it should be more
anonymous....

Any suggestions?

It could turn out that im trying to kill small birds with a gatlingun,
but.... :)
Kind regards

William Sullivan said:
I'm not all that familiar with the programming model of the good ol' ASP
days; but the bright new future with ASP.NET follows the Windows Forms design
model. Objects on the webpage correspond to objects in your code behind.
Prior to your code running, the viewstate of all the controls are
deserialized and the control objects are re-constructed for the postback
event. In your code, you would do something similar to this:

protected void Page_Load(object sender, EventArgs e)
{
UserSettings settings = this.Session["UserSettings"] as UserSettings;
if(settings == null)
{
settings = new UserSettings();
this.Session["UserSettings"] = settings;
}
settings.DOB = this.dateOfBirthCalendar.SelectedDate; // pseudo code
here, sorry
}


Bobstar said:
Hello.

In the good ol'ASP-days I allways handled all request vars within a class. I
want to do the same in ASP.NET. It can be done smart and maybe not so smart -
and I need help for the first part :)

I've the following:
public class UserSettings
{

System.Web.UI.Page _page;

public UserSettings(System.Web.UI.Page page)
{
this._page = page;
}
public DateTime Calendar1SelectedDate()
{
? this._page.FindControl("Calendar1");

}
}

But as you can see I allready stumpled across the calendarcontrol :-(
Can anybody put me in the right direction or maybe come up with a better
solution, maybe a designpattern?

Kind regards
 
G

Guest

Hello Ray

IMHO it's allways a bad idea, seen from a performance view, to place objects
in sessionsvariables. I usually only use the sessionobject to carry simple
types, that is ofcause only form a performance pov - If one have enough
memory and IO's there should'nt be a problem - but again just my openion.

The "normal" way I refer to is just that I should now alot of for example a
CalendarControl or maybe a dropdown to get any data from it when a user make
a request. For instance; I need to know it's a Calendar and therefore cast it
as a Calendar just to get simple info from it - certainly if I wanted to do
anything special with it I would threat it as a Calendar control... but for
about 95% of the times a CalendarControl is in use are very simple requests,
ie. DateSelected etc. This also goes on with the dropdown and more "simple"
controls! - Ofcause this could lead to a very "open" variantcontrol.. but
maybe some sort of dynamic variablepage where all PageVariables are available
as some sort of an ID take for instance:
string dateSelected = ControlID("Calendar1").Value.ToString()
or
string name = ControlID("txtName").Value.ToString()

I've used "value" as a very open property, but I cant see why things should
be more complicated all over - please notice this should be done around 95%
of all coincidences.

I hope I've answered your question.

Kind regards


Ray Booysen said:
Hi Bobstar

Why is putting an object into session a bad idea?
What is this "normal" way you know about controls?
And what do you mean by doing things in a more anonymous way?
Hello William, thank you for your quick response.

Unfortunately that's not what im looking for. The solution you proposed are
allready breaking a couple of things in my world....
An object into a session - not recommended. Well anyway, I would like a
more, "seen from an arcithectural point of view" - designpattern :) I've to
know a lot about the controls in the "normal" way, and it should be more
anonymous....

Any suggestions?

It could turn out that im trying to kill small birds with a gatlingun,
but.... :)
Kind regards

William Sullivan said:
I'm not all that familiar with the programming model of the good ol' ASP
days; but the bright new future with ASP.NET follows the Windows Forms design
model. Objects on the webpage correspond to objects in your code behind.
Prior to your code running, the viewstate of all the controls are
deserialized and the control objects are re-constructed for the postback
event. In your code, you would do something similar to this:

protected void Page_Load(object sender, EventArgs e)
{
UserSettings settings = this.Session["UserSettings"] as UserSettings;
if(settings == null)
{
settings = new UserSettings();
this.Session["UserSettings"] = settings;
}
settings.DOB = this.dateOfBirthCalendar.SelectedDate; // pseudo code
here, sorry
}


:

Hello.

In the good ol'ASP-days I allways handled all request vars within a class. I
want to do the same in ASP.NET. It can be done smart and maybe not so smart -
and I need help for the first part :)

I've the following:
public class UserSettings
{

System.Web.UI.Page _page;

public UserSettings(System.Web.UI.Page page)
{
this._page = page;
}
public DateTime Calendar1SelectedDate()
{
? this._page.FindControl("Calendar1");

}
}

But as you can see I allready stumpled across the calendarcontrol :-(
Can anybody put me in the right direction or maybe come up with a better
solution, maybe a designpattern?

Kind regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top