Events generation and handling within a server controls.

Discussion in 'ASP .Net' started by luca, Dec 9, 2003.

  1. luca

    luca Guest

    I'm trying to build a Server Control, it's a calendar to manage sellers
    appointments (don't answer me to use and custumize Calendar Control because
    unluckily it's not possible for this specific project).
    A piece of my control's interface is composed of a table and in each of its
    cells are stored informations about a seller, a date and a time range.
    Each of these cells has to be an interactive element: I should be able to
    process datas related to the clicked cell.
    I've some problems joinig datas to each cell and managing events generated
    from the cells within my server control:

    At the moment I've implemented the table, within my Server Control, putting
    an ImageButton in each cell and defining an event handler function
    ("DateIButton_Command" in the code below) for each ImageButton:

    protected override void CreateChildControls()
    {
    ....
    for(...)
    {
    .....
    DateIButton = new ImageButton();
    DateIButton.CommandArgument = "9/12/2003";
    DateIButton.Command += new CommandEventHandler(DateIButton_Command);
    ...
    }
    }

    And then defining the event handler:

    private void DateIButton_Command(object sender, CommandEventArgs e)
    {
    ExplodeDay(e.CommandArgument.ToString ());
    }

    The method works, but it has two great problems:
    1) When I click on one of the ImageButtons and the page is posted back,
    "CreateChildControls" (I use this one as rendering function, is it correct?)
    is executed before than "DateIButton_Command". It's a problem because
    "DateIButton_Command" sets some variables that the rendering function
    "CreateChildControls" has to use in order change graphic interface's
    appareance.
    2)Using "DateIButton.CommandArgument" I can't assign no more than one single
    string as argument for my event handler function "DateIButton_Command". And
    I need to give it more than one argument.

    How can I solve these problems? Am I using a wrong approach?

    Another question: in .NET Calendar Control, it is possible to catch the
    DayRender event to customize the rendering function of each single cell of
    the calendar. Unluckily I can't use this control for my project, how can I
    similarly build a Server Control which generates events which can be
    caught and handled from its container?

    Thanks in advance.
    Luca.
     
    luca, Dec 9, 2003
    #1
    1. Advertising

  2. luca

    Teemu Keiski Guest

    Hi,

    CreateChildControls is, as its name implies, meant for child control
    creation and it is called at the time child controls need to be created,
    that is usually before postback data handling and at the latest at PreRender
    stage. So result is that on postback it is most often (=always) called
    before postback events because in fact, postback events cannot be raised
    unless controls are created.

    If you want to customize the rendering, do that in the Render phase of the
    control, that means create the controls as normally at the
    CreateChildControls and do the customizing based on parameters at PreRender
    or actual Render.

    About the command arguments, one way is to put them as comma or semicolon
    separated into CommandArgument property.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist


    "luca" <> wrote in message
    news:GZmBb.18140$...
    > I'm trying to build a Server Control, it's a calendar to manage sellers
    > appointments (don't answer me to use and custumize Calendar Control

    because
    > unluckily it's not possible for this specific project).
    > A piece of my control's interface is composed of a table and in each of

    its
    > cells are stored informations about a seller, a date and a time range.
    > Each of these cells has to be an interactive element: I should be able to
    > process datas related to the clicked cell.
    > I've some problems joinig datas to each cell and managing events generated
    > from the cells within my server control:
    >
    > At the moment I've implemented the table, within my Server Control,

    putting
    > an ImageButton in each cell and defining an event handler function
    > ("DateIButton_Command" in the code below) for each ImageButton:
    >
    > protected override void CreateChildControls()
    > {
    > ...
    > for(...)
    > {
    > .....
    > DateIButton = new ImageButton();
    > DateIButton.CommandArgument = "9/12/2003";
    > DateIButton.Command += new CommandEventHandler(DateIButton_Command);
    > ...
    > }
    > }
    >
    > And then defining the event handler:
    >
    > private void DateIButton_Command(object sender, CommandEventArgs e)
    > {
    > ExplodeDay(e.CommandArgument.ToString ());
    > }
    >
    > The method works, but it has two great problems:
    > 1) When I click on one of the ImageButtons and the page is posted back,
    > "CreateChildControls" (I use this one as rendering function, is it

    correct?)
    > is executed before than "DateIButton_Command". It's a problem because
    > "DateIButton_Command" sets some variables that the rendering function
    > "CreateChildControls" has to use in order change graphic interface's
    > appareance.
    > 2)Using "DateIButton.CommandArgument" I can't assign no more than one

    single
    > string as argument for my event handler function "DateIButton_Command".

    And
    > I need to give it more than one argument.
    >
    > How can I solve these problems? Am I using a wrong approach?
    >
    > Another question: in .NET Calendar Control, it is possible to catch the
    > DayRender event to customize the rendering function of each single cell of
    > the calendar. Unluckily I can't use this control for my project, how can I
    > similarly build a Server Control which generates events which can be
    > caught and handled from its container?
    >
    > Thanks in advance.
    > Luca.
    >
    >
     
    Teemu Keiski, Dec 9, 2003
    #2
    1. Advertising

  3. luca

    luca Guest

    Tank you for your explanations.
    My doubt is that, with this kind of architecture, during CreateChildControls
    stage I have to create more child controls than I actually need and then, in
    PreRender or Render stage, renderize only the elements I actually need using
    informations posted back from my buttons; I can't decide it in
    CreateChildControls stage because I still not have the information I need to
    do that. It's not computationally chep.

    "Teemu Keiski" <> ha scritto nel messaggio
    news:O9$...
    > Hi,
    >
    > CreateChildControls is, as its name implies, meant for child control
    > creation and it is called at the time child controls need to be created,
    > that is usually before postback data handling and at the latest at

    PreRender
    > stage. So result is that on postback it is most often (=always) called
    > before postback events because in fact, postback events cannot be raised
    > unless controls are created.
    >
    > If you want to customize the rendering, do that in the Render phase of the
    > control, that means create the controls as normally at the
    > CreateChildControls and do the customizing based on parameters at

    PreRender
    > or actual Render.
    >
    > About the command arguments, one way is to put them as comma or semicolon
    > separated into CommandArgument property.
    >
    > --
    > Teemu Keiski
    > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > ASP.NET Forum Moderator, AspAlliance Columnist
    >
    >
    > "luca" <> wrote in message
    > news:GZmBb.18140$...
    > > I'm trying to build a Server Control, it's a calendar to manage sellers
    > > appointments (don't answer me to use and custumize Calendar Control

    > because
    > > unluckily it's not possible for this specific project).
    > > A piece of my control's interface is composed of a table and in each of

    > its
    > > cells are stored informations about a seller, a date and a time range.
    > > Each of these cells has to be an interactive element: I should be able

    to
    > > process datas related to the clicked cell.
    > > I've some problems joinig datas to each cell and managing events

    generated
    > > from the cells within my server control:
    > >
    > > At the moment I've implemented the table, within my Server Control,

    > putting
    > > an ImageButton in each cell and defining an event handler function
    > > ("DateIButton_Command" in the code below) for each ImageButton:
    > >
    > > protected override void CreateChildControls()
    > > {
    > > ...
    > > for(...)
    > > {
    > > .....
    > > DateIButton = new ImageButton();
    > > DateIButton.CommandArgument = "9/12/2003";
    > > DateIButton.Command += new

    CommandEventHandler(DateIButton_Command);
    > > ...
    > > }
    > > }
    > >
    > > And then defining the event handler:
    > >
    > > private void DateIButton_Command(object sender, CommandEventArgs e)
    > > {
    > > ExplodeDay(e.CommandArgument.ToString ());
    > > }
    > >
    > > The method works, but it has two great problems:
    > > 1) When I click on one of the ImageButtons and the page is posted back,
    > > "CreateChildControls" (I use this one as rendering function, is it

    > correct?)
    > > is executed before than "DateIButton_Command". It's a problem because
    > > "DateIButton_Command" sets some variables that the rendering function
    > > "CreateChildControls" has to use in order change graphic interface's
    > > appareance.
    > > 2)Using "DateIButton.CommandArgument" I can't assign no more than one

    > single
    > > string as argument for my event handler function "DateIButton_Command".

    > And
    > > I need to give it more than one argument.
    > >
    > > How can I solve these problems? Am I using a wrong approach?
    > >
    > > Another question: in .NET Calendar Control, it is possible to catch the
    > > DayRender event to customize the rendering function of each single cell

    of
    > > the calendar. Unluckily I can't use this control for my project, how can

    I
    > > similarly build a Server Control which generates events which can be
    > > caught and handled from its container?
    > >
    > > Thanks in advance.
    > > Luca.
    > >
    > >

    >
    >
     
    luca, Dec 9, 2003
    #3
    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. newbye
    Replies:
    0
    Views:
    586
    newbye
    Jul 6, 2006
  2. SevDer
    Replies:
    2
    Views:
    1,319
    Walter Wang [MSFT]
    Nov 13, 2007
  3. Piyush
    Replies:
    0
    Views:
    109
    Piyush
    Sep 28, 2004
  4. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    404
    Chris
    Aug 30, 2005
  5. John W. Long

    HTML Generation (Next Generation CGI)

    John W. Long, Nov 22, 2003, in forum: Ruby
    Replies:
    4
    Views:
    376
    John W. Long
    Nov 24, 2003
Loading...

Share This Page