Events Handling Order

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Events Handling Order

    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 Guest

  2. Similar Questions and Discussions

    1. Order of events
      I have a form with several controls on it, one control has a drop down list. When a user selects an item in that drop down list, I want everything...
    2. (vb.net) Handling user-control events
      I created a web-project containg an .aspx file and a self- made User-Control (.acsx file) - all in vb.net. My aspx file contains a Submit button...
    3. Handling events in container controls?
      Hi, I have a sub in a user control that looks like this: Public Sub BatchDetail_ItemCommand(ByVal Sender As Object, ByVal e As...
    4. Handling events in a datagrid
      Hi, I am having a datagrid with 3 radiobuttons in one template column and a textbox in another template column. How can I disable or enable the...
    5. Handling Events in Nested Controls
      Hi, I have nested User Controls like below. User_Control_1 User_Control_11 User_Control_12(contains method DisplayMessage) ...
  3. #2

    Default Re: Events Handling Order

    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:
    [url]http://obies.com/vga/blog.aspx[/url]

    To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    "Igor" <IgorRubinovich@yahoo.com> wrote in message
    news:3a4989f7.0311251704.5efb91be@posting.google.c om...
    > 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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139