Pattern/ help wanted for Request

Discussion in 'ASP .Net' started by =?Utf-8?B?Qm9ic3Rhcg==?=, Jul 3, 2006.

  1. 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
    =?Utf-8?B?Qm9ic3Rhcg==?=, Jul 3, 2006
    #1
    1. Advertising

  2. 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" wrote:

    > 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
    >
    =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=, Jul 3, 2006
    #2
    1. Advertising

  3. 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" wrote:

    > 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" wrote:
    >
    > > 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
    > >
    =?Utf-8?B?Qm9ic3Rhcg==?=, Jul 3, 2006
    #3
  4. =?Utf-8?B?Qm9ic3Rhcg==?=

    Ray Booysen Guest

    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?

    Bobstar wrote:
    > 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" wrote:
    >
    >> 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" wrote:
    >>
    >>> 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
    >>>
    Ray Booysen, Jul 3, 2006
    #4
  5. 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" wrote:

    > 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" wrote:
    >
    > > 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" wrote:
    > >
    > > > 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
    > > >
    =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=, Jul 3, 2006
    #5
  6. 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" wrote:

    > 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?
    >
    > Bobstar wrote:
    > > 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" wrote:
    > >
    > >> 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" wrote:
    > >>
    > >>> 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
    > >>>

    >
    =?Utf-8?B?Qm9ic3Rhcg==?=, Jul 3, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Birtle
    Replies:
    2
    Views:
    1,996
    John Saunders
    Oct 16, 2003
  2. Harvey
    Replies:
    0
    Views:
    676
    Harvey
    Jul 16, 2004
  3. Harvey
    Replies:
    1
    Views:
    823
    Daniel
    Jul 16, 2004
  4. Replies:
    17
    Views:
    1,844
    Chris Uppal
    Nov 16, 2005
  5. sunny
    Replies:
    1
    Views:
    451
    Salt_Peter
    Dec 7, 2006
Loading...

Share This Page