Events Handling Order

Discussion in 'ASP .Net Building Controls' started by Igor, Nov 26, 2003.

  1. Igor

    Igor Guest

    Hi all,
    I'm a total newbie, so this might be stupid...
    Anyway, I've created an expanding tree of categories control, based on
    DataList.
    It works almost fine, but I can't make it return the value of the last
    category clicked.
    To be more specific, it does return it, but only the second time I click the
    category.
    For example, if I click category 5 and then 8, it shows 5 and clicking later
    on 3 shows 8.

    It goes like this:

    ..
    ..
    ..
    public property CategoryID
    Get
    if(ViewState("CurrentCategory") = Nothing)
    CategoryID = 1
    else
    CategoryID = ViewState("CurrentCategory").ToString
    end if
    End Get
    Set

    ViewState("CurrentCategory") = value
    End Set
    end property

    ..
    ..
    ..

    sub CategoriesDataList_ItemCommand(sender As Object, e as
    DataListCommandEventArgs)
    CategoryID = e.CommandArgument
    CategoriesDataList.DataSource = GetCategoriesTree(e.CommandArgument)
    DataBind
    CategoriesDataList.SelectedIndex = e.Item.ItemIndex
    End Sub

    The real big problem, as much as I could figure it out is that the
    CategoriesDataList_ItemCommand event is processed AFTER the Page_Load event
    of the parent page is. So, when i write something like

    [assume CategoriesTree is a CategoriesDataList control]

    msg.Text = CategoriesTree.CategoryID

    in the parent page, the value shown in msg is the old one (taken from
    ViewState bag).


    Thanks for any help,
    Igor.
     
    Igor, Nov 26, 2003
    #1
    1. Advertising

  2. Hi Igor,

    If you need to handle values that will be updated by a click events use an
    event that fires *after* the handling of click events, i.e.: PreRender. As
    you've discovered the Load event fires *before* the handling of events so
    you can't count on such values to be updated at that point.

    --
    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    http://obies.com/vga/blog.aspx

    To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    "Igor" <> wrote in message
    news:...
    > Hi all,
    > I'm a total newbie, so this might be stupid...
    > Anyway, I've created an expanding tree of categories control, based on
    > DataList.
    > It works almost fine, but I can't make it return the value of the last
    > category clicked.
    > To be more specific, it does return it, but only the second time I click

    the
    > category.
    > For example, if I click category 5 and then 8, it shows 5 and clicking

    later
    > on 3 shows 8.
    >
    > It goes like this:
    >
    > .
    > .
    > .
    > public property CategoryID
    > Get
    > if(ViewState("CurrentCategory") = Nothing)
    > CategoryID = 1
    > else
    > CategoryID = ViewState("CurrentCategory").ToString
    > end if
    > End Get
    > Set
    >
    > ViewState("CurrentCategory") = value
    > End Set
    > end property
    >
    > .
    > .
    > .
    >
    > sub CategoriesDataList_ItemCommand(sender As Object, e as
    > DataListCommandEventArgs)
    > CategoryID = e.CommandArgument
    > CategoriesDataList.DataSource = GetCategoriesTree(e.CommandArgument)
    > DataBind
    > CategoriesDataList.SelectedIndex = e.Item.ItemIndex
    > End Sub
    >
    > The real big problem, as much as I could figure it out is that the
    > CategoriesDataList_ItemCommand event is processed AFTER the Page_Load

    event
    > of the parent page is. So, when i write something like
    >
    > [assume CategoriesTree is a CategoriesDataList control]
    >
    > msg.Text = CategoriesTree.CategoryID
    >
    > in the parent page, the value shown in msg is the old one (taken from
    > ViewState bag).
    >
    >
    > Thanks for any help,
    > Igor.
     
    Victor Garcia Aprea, Nov 26, 2003
    #2
    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. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    order of events - dynamic checkbox events

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Aug 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    596
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    Aug 17, 2005
  2. Soren Kuula
    Replies:
    2
    Views:
    541
    Soren Kuula
    Feb 1, 2004
  3. cspoh
    Replies:
    0
    Views:
    267
    cspoh
    Jul 31, 2003
  4. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    420
    Chris
    Aug 30, 2005
  5. Stephan Kämper
    Replies:
    2
    Views:
    257
    Stephan Kämper
    Jan 18, 2004
Loading...

Share This Page