Problem with AddHandler (New CommandEventHandler) under framework 2.0

Discussion in 'ASP .Net' started by Fabrice, Jun 25, 2009.

  1. Fabrice

    Fabrice Guest

    Hello

    This code works under framework 1.1. I add in the header an image with a
    command event to execute a sub on click.
    It work fine with 1.1. But not under 2.0.

    I think the problem could be with the declaration :AddHandler
    myBtnLibEveUp.Command, New CommandEventHandler(AddressOf myImgButtonSorting)

    Is there a way to build a control and add an command handler ?

    thanks for your help
    fabrice


    Code to add my first image button.

    Sub my009DataGrid_ItemCreated(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs)

    If e.Item.ItemType = ListItemType.Header Then

    'Add Control ImageButton UP LIBEVE.
    Dim myBtnLibEveUp As New ImageButton
    With myBtnLibEveUp
    .ImageUrl="/img/gen/up.gif"
    .EnableViewState = ctype("False",Boolean)
    .CausesValidation=ctype("False",Boolean)
    .Attributes.Add("runat", "server")
    .Attributes.Add("onMouseOver", "window.status=' '; return true;")
    .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveUp","patent.aspx")
    .Id="myBtnLibEveUp"
    .CommandArgument="LIBEVE ASC"
    AddHandler myBtnLibEveUp.Command, New CommandEventHandler(AddressOf
    myImgButtonSorting)
    End With

    .....

    The procedure :

    Sub myImgButtonSorting (sender As Object, e As
    System.Web.UI.WebControls.CommandEventArgs)

    response.write("test")

    end sud
     
    Fabrice, Jun 25, 2009
    #1
    1. Advertising

  2. Fabrice

    Lloyd Sheen Guest

    "Fabrice" <> wrote in message
    news:...
    > Hello
    >
    > This code works under framework 1.1. I add in the header an image with a
    > command event to execute a sub on click.
    > It work fine with 1.1. But not under 2.0.
    >
    > I think the problem could be with the declaration :AddHandler
    > myBtnLibEveUp.Command, New CommandEventHandler(AddressOf
    > myImgButtonSorting)
    >
    > Is there a way to build a control and add an command handler ?
    >
    > thanks for your help
    > fabrice
    >
    >
    > Code to add my first image button.
    >
    > Sub my009DataGrid_ItemCreated(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.DataGridItemEventArgs)
    >
    > If e.Item.ItemType = ListItemType.Header Then
    >
    > 'Add Control ImageButton UP LIBEVE.
    > Dim myBtnLibEveUp As New ImageButton
    > With myBtnLibEveUp
    > .ImageUrl="/img/gen/up.gif"
    > .EnableViewState = ctype("False",Boolean)
    > .CausesValidation=ctype("False",Boolean)
    > .Attributes.Add("runat", "server")
    > .Attributes.Add("onMouseOver", "window.status=' '; return true;")
    >
    > .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveUp","patent.aspx")
    > .Id="myBtnLibEveUp"
    > .CommandArgument="LIBEVE ASC"
    > AddHandler myBtnLibEveUp.Command, New CommandEventHandler(AddressOf
    > myImgButtonSorting)
    > End With
    >
    > ....
    >
    > The procedure :
    >
    > Sub myImgButtonSorting (sender As Object, e As
    > System.Web.UI.WebControls.CommandEventArgs)
    >
    > response.write("test")
    >
    > end sud
    >


    I don't see any code to add the control to the page.

    LS
     
    Lloyd Sheen, Jun 25, 2009
    #2
    1. Advertising

  3. Fabrice

    Fabrice Guest

    More about my code : Problem with AddHandler (New CommandEventHandler) under framework 2.0

    Sorry. This is my code :

    In my aspx file, I have a datagrid with the "OnItemCreated" parameter.
    In my code behind (VB file), I have built all the buttons by code
    (ImageButton).

    The Handler on the differents ImageButtons seems not be fire under .net 2.0
    It is ok under 1.1

    In my datagrid The parameter OnItemCreated is
    OnItemCreated="my009DataGrid_ItemCreated"
    (see part 2)

    part 1/ My code file in my .vb file
    ------------------------------------


    Sub my009DataGrid_ItemCreated(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs)

    If e.Item.ItemType = ListItemType.Header Then

    'ImageButton Header column : e.Item.Cells(0)

    Dim myLibEve As New Label
    With myLibEve
    .Id="myLibEve"
    .Text=myLocalization.EasyResourceManager.myGetString("myLibEve","patent.aspx")
    .EnableViewState = ctype("False",Boolean)
    .CssClass="txtOres2"
    .Attributes.Add("runat", "server")
    End With

    'ADD Control ImageButton UP LIBEVE.
    Dim myBtnLibEveUp As New ImageButton
    With myBtnLibEveUp
    .ImageUrl="/img/gen/up.gif"
    .EnableViewState = ctype("False",Boolean)
    .CausesValidation=ctype("False",Boolean)
    .Attributes.Add("runat", "server")
    .Attributes.Add("onMouseOver", "window.status=' '; return true;")
    .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveUp","patent.aspx")
    .Id="myBtnLibEveUp"
    .CommandArgument="LIBEVE ASC"
    AddHandler myBtnLibEveUp.Command, New CommandEventHandler(AddressOf
    myImgButtonSorting)
    End With

    'ADD Control ImageButton DOWN LIBEVE.
    Dim myBtnLibEveDown As New ImageButton
    With myBtnLibEveDown
    ..ImageUrl="/img/gen/down.gif"
    ..EnableViewState = ctype("False",Boolean)
    ..CausesValidation=ctype("False",Boolean)
    ..Attributes.Add("runat", "server")
    ..Attributes.Add("onMouseOver", "window.status=' '; return true;")
    ..AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveDown","patent.aspx")
    ..Id="myBtnLibEveDown"
    ..CommandArgument="LIBEVE DESC"
    AddHandler myBtnLibEveDown.Command, New CommandEventHandler(AddressOf
    myImgButtonSorting)
    End With

    'Add controls in e.Item.Cells(0)
    e.Item.Cells(0).Controls.Add(myLibEve)
    e.Item.Cells(0).Controls.Add(myBtnLibEveUp)
    e.Item.Cells(0).Controls.Add(myBtnLibEveDown)


    myLibEve.Dispose()
    myLibEve=Nothing
    myBtnLibEveUp.Dispose()
    myBtnLibEveUp=Nothing
    myBtnLibEveDown.Dispose()
    myBtnLibEveDown=Nothing

    'Texte de la Colonne Header : e.Item.Cells(1)
    'Label Colonne DATECH.
    Dim myDatEch As New Label
    With myDatEch
    .Id="myDatEch"
    .Text=myLocalization.EasyResourceManager.myGetString("myDatEch","patent.aspx")
    .EnableViewState = ctype("False",Boolean)
    .CssClass="txtOres2"
    .Attributes.Add("runat", "server")
    End With

    'Ajout Control ImageButton UP DATECH.
    Dim myBtnDatEchUp As New ImageButton
    With myBtnDatEchUp
    .ImageUrl="/img/gen/up.gif"
    .EnableViewState = ctype("False",Boolean)
    .CausesValidation=ctype("False",Boolean)
    .Attributes.Add("runat", "server")
    .Attributes.Add("onMouseOver", "window.status=' '; return true;")
    .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveUp","patent.aspx")
    .Id="myBtnDatEchUp"
    .CommandArgument="DATECH ASC"
    AddHandler myBtnDatEchUp.Command, New CommandEventHandler(AddressOf
    myImgButtonSorting)
    End With

    'Ajout Control ImageButton DOWN DATECH.
    Dim myBtnDatEchDown As New ImageButton
    With myBtnDatEchDown
    .ImageUrl="/img/gen/down.gif"
    .EnableViewState = ctype("False",Boolean)
    .CausesValidation=ctype("False",Boolean)
    .Attributes.Add("runat", "server")
    .Attributes.Add("onMouseOver", "window.status=' '; return true;")
    .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveDown","patent.aspx")
    .Id="myBtnDatEchDown"
    .CommandArgument="DATECH DESC"
    AddHandler myBtnDatEchDown.Command, New CommandEventHandler(AddressOf
    myImgButtonSorting)
    End With

    'Ajout Effectif dans e.Item.Cells(0)
    e.Item.Cells(1).Controls.Add(myDatEch)
    e.Item.Cells(1).Controls.Add(myBtnDatEchUp)
    e.Item.Cells(1).Controls.Add(myBtnDatEchDown)

    'Libération Mémoire des trois Controls
    myDatEch.Dispose()
    myDatEch=Nothing
    myBtnDatEchUp.Dispose()
    myBtnDatEchUp=Nothing
    myBtnDatEchDown.Dispose()
    myBtnDatEchDown=Nothing

    'Texte de la Colonne Header : e.Item.Cells(2)
    'Label Colonne NATURE.
    Dim myNature As New Label
    With myNature
    .Id="myNature"
    .Text=myLocalization.EasyResourceManager.myGetString("myNature","patent.aspx")
    .EnableViewState = ctype("False",Boolean)
    .CssClass="txtOres2"
    .Attributes.Add("runat", "server")
    End With

    'Ajout Effectif dans e.Item.Cells(0)
    e.Item.Cells(2).Controls.Add(myNature)

    'Libération Mémoire des trois Controls
    myNature.Dispose()
    myNature=Nothing

    End If '.Item.ItemType = ListItemType.Header

    End Sub 'my009DataGrid_ItemCreated


    part 2/ In .aspx file : My datagrid with OnItemCreated parameter

    <asp:DataGrid id="my009DataGrid"
    runat="server"
    FooterStyle-BorderWidth="0"
    ShowFooter="False"
    FooterStyle-BackColor="#F29168"
    FooterStyle-ForeColor="#FFFFFF"
    FooterStyle-BorderStyle= "None"
    PagerStyle-Mode="NumericPages"
    PageCount="1"
    AutoGenerateColumns="False"
    borderwidth="1"
    bordercolor="black"
    BorderStyle="Solid"
    PagerStyle-VerticalAlign="top"
    Cellpadding="1"
    Cellspacing="0"
    ShowHeader="True"
    HeaderStyle-ForeColor="White"
    HeaderStyle-Font-Bold="False"
    HeaderStyle-HorizontalAlign="Center"
    HeaderStyle-VerticalAlign="Middle"
    AllowSorting="False"
    AllowPaging="True"
    OnPageIndexChanged="PageIndexChanged_OnClick"
    OnItemCreated="my009DataGrid_ItemCreated"
    PageSize="5"
    width="100%"
    HeaderStyle-BackColor="#93b0cc"
    BackColor="#e5ecf2"
    AlternatingItemStyle-BackColor="#e5ecf2"
    PagerStyle-Backcolor="#93b0cc"
    PagerStyle-Forecolor="Black"
    PagerStyle-HorizontalAlign="Right"
    PagerStyle-BorderStyle="Inset">

    <Columns>
    <asp:BoundColumn DataField="libeve" ReadOnly="true">
    <ItemStyle Font-Names="Times New Roman, Times, serif" ForeColor="#003B6F"
    Font-Size="10" horizontalalign="Left" VerticalAlign="Middle" width="40%">
    </ItemStyle>
    </asp:BoundColumn>

    <asp:BoundColumn DataField="datech" DataFormatString="{0:d}"
    ReadOnly="true">
    <ItemStyle Font-Names="Times New Roman, Times, serif" ForeColor="#003B6F"
    Font-Size="10" horizontalalign="Center" VerticalAlign="Middle" width="30%">
    </ItemStyle>
    </asp:BoundColumn>

    <asp:BoundColumn DataField="nature" ReadOnly="true" HeaderText="Nature">
    <ItemStyle Font-Names="Times New Roman, Times, serif" ForeColor="#003B6F"
    Font-Size="10" horizontalalign="Center" VerticalAlign="Middle" width="30%">
    </ItemStyle>
    </asp:BoundColumn>
    </Columns>

    </asp:DataGrid>



    thanks for your help
     
    Fabrice, Jun 25, 2009
    #3
  4. Fabrice

    Lloyd Sheen Guest

    Re: More about my code : Problem with AddHandler (New CommandEventHandler) under framework 2.0

    "Fabrice" <> wrote in message
    news:us%...
    > Sorry. This is my code :
    >
    > In my aspx file, I have a datagrid with the "OnItemCreated" parameter.
    > In my code behind (VB file), I have built all the buttons by code
    > (ImageButton).
    >
    > The Handler on the differents ImageButtons seems not be fire under .net
    > 2.0
    > It is ok under 1.1
    >
    > In my datagrid The parameter OnItemCreated is
    > OnItemCreated="my009DataGrid_ItemCreated"
    > (see part 2)
    >
    > part 1/ My code file in my .vb file
    > ------------------------------------
    >
    >
    > Sub my009DataGrid_ItemCreated(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.DataGridItemEventArgs)
    >
    > If e.Item.ItemType = ListItemType.Header Then
    >
    > 'ImageButton Header column : e.Item.Cells(0)
    >
    > Dim myLibEve As New Label
    > With myLibEve
    > .Id="myLibEve"
    >
    > .Text=myLocalization.EasyResourceManager.myGetString("myLibEve","patent.aspx")
    > .EnableViewState = ctype("False",Boolean)
    > .CssClass="txtOres2"
    > .Attributes.Add("runat", "server")
    > End With
    >
    > 'ADD Control ImageButton UP LIBEVE.
    > Dim myBtnLibEveUp As New ImageButton
    > With myBtnLibEveUp
    > .ImageUrl="/img/gen/up.gif"
    > .EnableViewState = ctype("False",Boolean)
    > .CausesValidation=ctype("False",Boolean)
    > .Attributes.Add("runat", "server")
    > .Attributes.Add("onMouseOver", "window.status=' '; return true;")
    >
    > .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveUp","patent.aspx")
    > .Id="myBtnLibEveUp"
    > .CommandArgument="LIBEVE ASC"
    > AddHandler myBtnLibEveUp.Command, New CommandEventHandler(AddressOf
    > myImgButtonSorting)
    > End With
    >
    > 'ADD Control ImageButton DOWN LIBEVE.
    > Dim myBtnLibEveDown As New ImageButton
    > With myBtnLibEveDown
    > .ImageUrl="/img/gen/down.gif"
    > .EnableViewState = ctype("False",Boolean)
    > .CausesValidation=ctype("False",Boolean)
    > .Attributes.Add("runat", "server")
    > .Attributes.Add("onMouseOver", "window.status=' '; return true;")
    > .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveDown","patent.aspx")
    > .Id="myBtnLibEveDown"
    > .CommandArgument="LIBEVE DESC"
    > AddHandler myBtnLibEveDown.Command, New CommandEventHandler(AddressOf
    > myImgButtonSorting)
    > End With
    >
    > 'Add controls in e.Item.Cells(0)
    > e.Item.Cells(0).Controls.Add(myLibEve)
    > e.Item.Cells(0).Controls.Add(myBtnLibEveUp)
    > e.Item.Cells(0).Controls.Add(myBtnLibEveDown)
    >
    >
    > myLibEve.Dispose()
    > myLibEve=Nothing
    > myBtnLibEveUp.Dispose()
    > myBtnLibEveUp=Nothing
    > myBtnLibEveDown.Dispose()
    > myBtnLibEveDown=Nothing
    >
    > 'Texte de la Colonne Header : e.Item.Cells(1)
    > 'Label Colonne DATECH.
    > Dim myDatEch As New Label
    > With myDatEch
    > .Id="myDatEch"
    >
    > .Text=myLocalization.EasyResourceManager.myGetString("myDatEch","patent.aspx")
    > .EnableViewState = ctype("False",Boolean)
    > .CssClass="txtOres2"
    > .Attributes.Add("runat", "server")
    > End With
    >
    > 'Ajout Control ImageButton UP DATECH.
    > Dim myBtnDatEchUp As New ImageButton
    > With myBtnDatEchUp
    > .ImageUrl="/img/gen/up.gif"
    > .EnableViewState = ctype("False",Boolean)
    > .CausesValidation=ctype("False",Boolean)
    > .Attributes.Add("runat", "server")
    > .Attributes.Add("onMouseOver", "window.status=' '; return
    > true;")
    >
    > .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveUp","patent.aspx")
    > .Id="myBtnDatEchUp"
    > .CommandArgument="DATECH ASC"
    > AddHandler myBtnDatEchUp.Command, New
    > CommandEventHandler(AddressOf
    > myImgButtonSorting)
    > End With
    >
    > 'Ajout Control ImageButton DOWN DATECH.
    > Dim myBtnDatEchDown As New ImageButton
    > With myBtnDatEchDown
    > .ImageUrl="/img/gen/down.gif"
    > .EnableViewState = ctype("False",Boolean)
    > .CausesValidation=ctype("False",Boolean)
    > .Attributes.Add("runat", "server")
    > .Attributes.Add("onMouseOver", "window.status=' '; return
    > true;")
    >
    > .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveDown","patent.aspx")
    > .Id="myBtnDatEchDown"
    > .CommandArgument="DATECH DESC"
    > AddHandler myBtnDatEchDown.Command, New
    > CommandEventHandler(AddressOf
    > myImgButtonSorting)
    > End With
    >
    > 'Ajout Effectif dans e.Item.Cells(0)
    > e.Item.Cells(1).Controls.Add(myDatEch)
    > e.Item.Cells(1).Controls.Add(myBtnDatEchUp)
    > e.Item.Cells(1).Controls.Add(myBtnDatEchDown)
    >
    > 'Libération Mémoire des trois Controls
    > myDatEch.Dispose()
    > myDatEch=Nothing
    > myBtnDatEchUp.Dispose()
    > myBtnDatEchUp=Nothing
    > myBtnDatEchDown.Dispose()
    > myBtnDatEchDown=Nothing
    >
    > 'Texte de la Colonne Header : e.Item.Cells(2)
    > 'Label Colonne NATURE.
    > Dim myNature As New Label
    > With myNature
    > .Id="myNature"
    >
    > .Text=myLocalization.EasyResourceManager.myGetString("myNature","patent.aspx")
    > .EnableViewState = ctype("False",Boolean)
    > .CssClass="txtOres2"
    > .Attributes.Add("runat", "server")
    > End With
    >
    > 'Ajout Effectif dans e.Item.Cells(0)
    > e.Item.Cells(2).Controls.Add(myNature)
    >
    > 'Libération Mémoire des trois Controls
    > myNature.Dispose()
    > myNature=Nothing
    >
    > End If '.Item.ItemType = ListItemType.Header
    >
    > End Sub 'my009DataGrid_ItemCreated
    >
    >
    > part 2/ In .aspx file : My datagrid with OnItemCreated parameter
    >
    > <asp:DataGrid id="my009DataGrid"
    > runat="server"
    > FooterStyle-BorderWidth="0"
    > ShowFooter="False"
    > FooterStyle-BackColor="#F29168"
    > FooterStyle-ForeColor="#FFFFFF"
    > FooterStyle-BorderStyle= "None"
    > PagerStyle-Mode="NumericPages"
    > PageCount="1"
    > AutoGenerateColumns="False"
    > borderwidth="1"
    > bordercolor="black"
    > BorderStyle="Solid"
    > PagerStyle-VerticalAlign="top"
    > Cellpadding="1"
    > Cellspacing="0"
    > ShowHeader="True"
    > HeaderStyle-ForeColor="White"
    > HeaderStyle-Font-Bold="False"
    > HeaderStyle-HorizontalAlign="Center"
    > HeaderStyle-VerticalAlign="Middle"
    > AllowSorting="False"
    > AllowPaging="True"
    > OnPageIndexChanged="PageIndexChanged_OnClick"
    > OnItemCreated="my009DataGrid_ItemCreated"
    > PageSize="5"
    > width="100%"
    > HeaderStyle-BackColor="#93b0cc"
    > BackColor="#e5ecf2"
    > AlternatingItemStyle-BackColor="#e5ecf2"
    > PagerStyle-Backcolor="#93b0cc"
    > PagerStyle-Forecolor="Black"
    > PagerStyle-HorizontalAlign="Right"
    > PagerStyle-BorderStyle="Inset">
    >
    > <Columns>
    > <asp:BoundColumn DataField="libeve" ReadOnly="true">
    > <ItemStyle Font-Names="Times New Roman, Times, serif" ForeColor="#003B6F"
    > Font-Size="10" horizontalalign="Left" VerticalAlign="Middle" width="40%">
    > </ItemStyle>
    > </asp:BoundColumn>
    >
    > <asp:BoundColumn DataField="datech" DataFormatString="{0:d}"
    > ReadOnly="true">
    > <ItemStyle Font-Names="Times New Roman, Times, serif" ForeColor="#003B6F"
    > Font-Size="10" horizontalalign="Center" VerticalAlign="Middle"
    > width="30%">
    > </ItemStyle>
    > </asp:BoundColumn>
    >
    > <asp:BoundColumn DataField="nature" ReadOnly="true" HeaderText="Nature">
    > <ItemStyle Font-Names="Times New Roman, Times, serif" ForeColor="#003B6F"
    > Font-Size="10" horizontalalign="Center" VerticalAlign="Middle"
    > width="30%">
    > </ItemStyle>
    > </asp:BoundColumn>
    > </Columns>
    >
    > </asp:DataGrid>
    >
    >
    >
    > thanks for your help


    I wonder why you are doing the dispose of the controls you create, I would
    think that one of the things that a dispose would do is remove all handlers.

    Hope this helps
    LS
     
    Lloyd Sheen, Jun 25, 2009
    #4
  5. Fabrice

    Fabrice Guest

    Re: More about my code : Problem with AddHandler (New CommandEventHandler) under framework 2.0

    Hello Lloyd

    Your are right. I removed the "dispose" of the controls I have created.
    And It works. I don't understand the difference of behavior between
    framework 1.1 and 2.0.

    If your can explain me.

    Thanks
    fabrice

    > think that one of the things that a dispose would do is remove all
    > handlers.


    Lloyd Sheen wrote:

    >
    > "Fabrice" <> wrote in message
    > news:us%...
    >> Sorry. This is my code :
    >>
    >> In my aspx file, I have a datagrid with the "OnItemCreated" parameter.
    >> In my code behind (VB file), I have built all the buttons by code
    >> (ImageButton).
    >>
    >> The Handler on the differents ImageButtons seems not be fire under .net
    >> 2.0
    >> It is ok under 1.1
    >>
    >> In my datagrid The parameter OnItemCreated is
    >> OnItemCreated="my009DataGrid_ItemCreated"
    >> (see part 2)
    >>
    >> part 1/ My code file in my .vb file
    >> ------------------------------------
    >>
    >>
    >> Sub my009DataGrid_ItemCreated(ByVal sender As Object, ByVal e As
    >> System.Web.UI.WebControls.DataGridItemEventArgs)
    >>
    >> If e.Item.ItemType = ListItemType.Header Then
    >>
    >> 'ImageButton Header column : e.Item.Cells(0)
    >>
    >> Dim myLibEve As New Label
    >> With myLibEve
    >> .Id="myLibEve"
    >>
    >> .Text=myLocalization.EasyResourceManager.myGetString("myLibEve","patent.aspx")
    >> .EnableViewState = ctype("False",Boolean)
    >> .CssClass="txtOres2"
    >> .Attributes.Add("runat", "server")
    >> End With
    >>
    >> 'ADD Control ImageButton UP LIBEVE.
    >> Dim myBtnLibEveUp As New ImageButton
    >> With myBtnLibEveUp
    >> .ImageUrl="/img/gen/up.gif"
    >> .EnableViewState = ctype("False",Boolean)
    >> .CausesValidation=ctype("False",Boolean)
    >> .Attributes.Add("runat", "server")
    >> .Attributes.Add("onMouseOver", "window.status=' '; return true;")
    >>
    >> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveUp","patent.aspx")
    >> .Id="myBtnLibEveUp"
    >> .CommandArgument="LIBEVE ASC"
    >> AddHandler myBtnLibEveUp.Command, New CommandEventHandler(AddressOf
    >> myImgButtonSorting)
    >> End With
    >>
    >> 'ADD Control ImageButton DOWN LIBEVE.
    >> Dim myBtnLibEveDown As New ImageButton
    >> With myBtnLibEveDown
    >> .ImageUrl="/img/gen/down.gif"
    >> .EnableViewState = ctype("False",Boolean)
    >> .CausesValidation=ctype("False",Boolean)
    >> .Attributes.Add("runat", "server")
    >> .Attributes.Add("onMouseOver", "window.status=' '; return true;")
    >> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveDown","patent.aspx")
    >> .Id="myBtnLibEveDown"
    >> .CommandArgument="LIBEVE DESC"
    >> AddHandler myBtnLibEveDown.Command, New CommandEventHandler(AddressOf
    >> myImgButtonSorting)
    >> End With
    >>
    >> 'Add controls in e.Item.Cells(0)
    >> e.Item.Cells(0).Controls.Add(myLibEve)
    >> e.Item.Cells(0).Controls.Add(myBtnLibEveUp)
    >> e.Item.Cells(0).Controls.Add(myBtnLibEveDown)
    >>
    >>
    >> myLibEve.Dispose()
    >> myLibEve=Nothing
    >> myBtnLibEveUp.Dispose()
    >> myBtnLibEveUp=Nothing
    >> myBtnLibEveDown.Dispose()
    >> myBtnLibEveDown=Nothing
    >>
    >> 'Texte de la Colonne Header : e.Item.Cells(1)
    >> 'Label Colonne DATECH.
    >> Dim myDatEch As New Label
    >> With myDatEch
    >> .Id="myDatEch"
    >>
    >> .Text=myLocalization.EasyResourceManager.myGetString("myDatEch","patent.aspx")
    >> .EnableViewState = ctype("False",Boolean)
    >> .CssClass="txtOres2"
    >> .Attributes.Add("runat", "server")
    >> End With
    >>
    >> 'Ajout Control ImageButton UP DATECH.
    >> Dim myBtnDatEchUp As New ImageButton
    >> With myBtnDatEchUp
    >> .ImageUrl="/img/gen/up.gif"
    >> .EnableViewState = ctype("False",Boolean)
    >> .CausesValidation=ctype("False",Boolean)
    >> .Attributes.Add("runat", "server")
    >> .Attributes.Add("onMouseOver", "window.status=' '; return
    >> true;")
    >>
    >> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveUp","patent.aspx")
    >> .Id="myBtnDatEchUp"
    >> .CommandArgument="DATECH ASC"
    >> AddHandler myBtnDatEchUp.Command, New
    >> CommandEventHandler(AddressOf
    >> myImgButtonSorting)
    >> End With
    >>
    >> 'Ajout Control ImageButton DOWN DATECH.
    >> Dim myBtnDatEchDown As New ImageButton
    >> With myBtnDatEchDown
    >> .ImageUrl="/img/gen/down.gif"
    >> .EnableViewState = ctype("False",Boolean)
    >> .CausesValidation=ctype("False",Boolean)
    >> .Attributes.Add("runat", "server")
    >> .Attributes.Add("onMouseOver", "window.status=' '; return
    >> true;")
    >>
    >> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveDown","patent.aspx")
    >> .Id="myBtnDatEchDown"
    >> .CommandArgument="DATECH DESC"
    >> AddHandler myBtnDatEchDown.Command, New
    >> CommandEventHandler(AddressOf
    >> myImgButtonSorting)
    >> End With
    >>
    >> 'Ajout Effectif dans e.Item.Cells(0)
    >> e.Item.Cells(1).Controls.Add(myDatEch)
    >> e.Item.Cells(1).Controls.Add(myBtnDatEchUp)
    >> e.Item.Cells(1).Controls.Add(myBtnDatEchDown)
    >>
    >> 'Libération Mémoire des trois Controls
    >> myDatEch.Dispose()
    >> myDatEch=Nothing
    >> myBtnDatEchUp.Dispose()
    >> myBtnDatEchUp=Nothing
    >> myBtnDatEchDown.Dispose()
    >> myBtnDatEchDown=Nothing
    >>
    >> 'Texte de la Colonne Header : e.Item.Cells(2)
    >> 'Label Colonne NATURE.
    >> Dim myNature As New Label
    >> With myNature
    >> .Id="myNature"
    >>
    >> .Text=myLocalization.EasyResourceManager.myGetString("myNature","patent.aspx")
    >> .EnableViewState = ctype("False",Boolean)
    >> .CssClass="txtOres2"
    >> .Attributes.Add("runat", "server")
    >> End With
    >>
    >> 'Ajout Effectif dans e.Item.Cells(0)
    >> e.Item.Cells(2).Controls.Add(myNature)
    >>
    >> 'Libération Mémoire des trois Controls
    >> myNature.Dispose()
    >> myNature=Nothing
    >>
    >> End If '.Item.ItemType = ListItemType.Header
    >>
    >> End Sub 'my009DataGrid_ItemCreated
    >>
    >>
    >> part 2/ In .aspx file : My datagrid with OnItemCreated parameter
    >>
    >> <asp:DataGrid id="my009DataGrid"
    >> runat="server"
    >> FooterStyle-BorderWidth="0"
    >> ShowFooter="False"
    >> FooterStyle-BackColor="#F29168"
    >> FooterStyle-ForeColor="#FFFFFF"
    >> FooterStyle-BorderStyle= "None"
    >> PagerStyle-Mode="NumericPages"
    >> PageCount="1"
    >> AutoGenerateColumns="False"
    >> borderwidth="1"
    >> bordercolor="black"
    >> BorderStyle="Solid"
    >> PagerStyle-VerticalAlign="top"
    >> Cellpadding="1"
    >> Cellspacing="0"
    >> ShowHeader="True"
    >> HeaderStyle-ForeColor="White"
    >> HeaderStyle-Font-Bold="False"
    >> HeaderStyle-HorizontalAlign="Center"
    >> HeaderStyle-VerticalAlign="Middle"
    >> AllowSorting="False"
    >> AllowPaging="True"
    >> OnPageIndexChanged="PageIndexChanged_OnClick"
    >> OnItemCreated="my009DataGrid_ItemCreated"
    >> PageSize="5"
    >> width="100%"
    >> HeaderStyle-BackColor="#93b0cc"
    >> BackColor="#e5ecf2"
    >> AlternatingItemStyle-BackColor="#e5ecf2"
    >> PagerStyle-Backcolor="#93b0cc"
    >> PagerStyle-Forecolor="Black"
    >> PagerStyle-HorizontalAlign="Right"
    >> PagerStyle-BorderStyle="Inset">
    >>
    >> <Columns>
    >> <asp:BoundColumn DataField="libeve" ReadOnly="true">
    >> <ItemStyle Font-Names="Times New Roman, Times, serif" ForeColor="#003B6F"
    >> Font-Size="10" horizontalalign="Left" VerticalAlign="Middle" width="40%">
    >> </ItemStyle>
    >> </asp:BoundColumn>
    >>
    >> <asp:BoundColumn DataField="datech" DataFormatString="{0:d}"
    >> ReadOnly="true">
    >> <ItemStyle Font-Names="Times New Roman, Times, serif" ForeColor="#003B6F"
    >> Font-Size="10" horizontalalign="Center" VerticalAlign="Middle"
    >> width="30%">
    >> </ItemStyle>
    >> </asp:BoundColumn>
    >>
    >> <asp:BoundColumn DataField="nature" ReadOnly="true" HeaderText="Nature">
    >> <ItemStyle Font-Names="Times New Roman, Times, serif" ForeColor="#003B6F"
    >> Font-Size="10" horizontalalign="Center" VerticalAlign="Middle"
    >> width="30%">
    >> </ItemStyle>
    >> </asp:BoundColumn>
    >> </Columns>
    >>
    >> </asp:DataGrid>
    >>
    >>
    >>
    >> thanks for your help

    >
    > I wonder why you are doing the dispose of the controls you create, I would
    > think that one of the things that a dispose would do is remove all
    > handlers.
    >
    > Hope this helps
    > LS
     
    Fabrice, Jun 25, 2009
    #5
  6. Fabrice

    Lloyd Sheen Guest

    Re: More about my code : Problem with AddHandler (New CommandEventHandler) under framework 2.0

    "Fabrice" <> wrote in message
    news:...
    > Hello Lloyd
    >
    > Your are right. I removed the "dispose" of the controls I have created.
    > And It works. I don't understand the difference of behavior between
    > framework 1.1 and 2.0.
    >
    > If your can explain me.
    >
    > Thanks
    > fabrice
    >
    >> think that one of the things that a dispose would do is remove all
    >> handlers.

    >
    > Lloyd Sheen wrote:
    >
    >>
    >> "Fabrice" <> wrote in message
    >> news:us%...
    >>> Sorry. This is my code :
    >>>
    >>> In my aspx file, I have a datagrid with the "OnItemCreated" parameter.
    >>> In my code behind (VB file), I have built all the buttons by code
    >>> (ImageButton).
    >>>
    >>> The Handler on the differents ImageButtons seems not be fire under .net
    >>> 2.0
    >>> It is ok under 1.1
    >>>
    >>> In my datagrid The parameter OnItemCreated is
    >>> OnItemCreated="my009DataGrid_ItemCreated"
    >>> (see part 2)
    >>>
    >>> part 1/ My code file in my .vb file
    >>> ------------------------------------
    >>>
    >>>
    >>> Sub my009DataGrid_ItemCreated(ByVal sender As Object, ByVal e As
    >>> System.Web.UI.WebControls.DataGridItemEventArgs)
    >>>
    >>> If e.Item.ItemType = ListItemType.Header Then
    >>>
    >>> 'ImageButton Header column : e.Item.Cells(0)
    >>>
    >>> Dim myLibEve As New Label
    >>> With myLibEve
    >>> .Id="myLibEve"
    >>>
    >>> .Text=myLocalization.EasyResourceManager.myGetString("myLibEve","patent.aspx")
    >>> .EnableViewState = ctype("False",Boolean)
    >>> .CssClass="txtOres2"
    >>> .Attributes.Add("runat", "server")
    >>> End With
    >>>
    >>> 'ADD Control ImageButton UP LIBEVE.
    >>> Dim myBtnLibEveUp As New ImageButton
    >>> With myBtnLibEveUp
    >>> .ImageUrl="/img/gen/up.gif"
    >>> .EnableViewState = ctype("False",Boolean)
    >>> .CausesValidation=ctype("False",Boolean)
    >>> .Attributes.Add("runat", "server")
    >>> .Attributes.Add("onMouseOver", "window.status=' '; return true;")
    >>>
    >>> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveUp","patent.aspx")
    >>> .Id="myBtnLibEveUp"
    >>> .CommandArgument="LIBEVE ASC"
    >>> AddHandler myBtnLibEveUp.Command, New CommandEventHandler(AddressOf
    >>> myImgButtonSorting)
    >>> End With
    >>>
    >>> 'ADD Control ImageButton DOWN LIBEVE.
    >>> Dim myBtnLibEveDown As New ImageButton
    >>> With myBtnLibEveDown
    >>> .ImageUrl="/img/gen/down.gif"
    >>> .EnableViewState = ctype("False",Boolean)
    >>> .CausesValidation=ctype("False",Boolean)
    >>> .Attributes.Add("runat", "server")
    >>> .Attributes.Add("onMouseOver", "window.status=' '; return true;")
    >>> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveDown","patent.aspx")
    >>> .Id="myBtnLibEveDown"
    >>> .CommandArgument="LIBEVE DESC"
    >>> AddHandler myBtnLibEveDown.Command, New CommandEventHandler(AddressOf
    >>> myImgButtonSorting)
    >>> End With
    >>>
    >>> 'Add controls in e.Item.Cells(0)
    >>> e.Item.Cells(0).Controls.Add(myLibEve)
    >>> e.Item.Cells(0).Controls.Add(myBtnLibEveUp)
    >>> e.Item.Cells(0).Controls.Add(myBtnLibEveDown)
    >>>
    >>>
    >>> myLibEve.Dispose()
    >>> myLibEve=Nothing
    >>> myBtnLibEveUp.Dispose()
    >>> myBtnLibEveUp=Nothing
    >>> myBtnLibEveDown.Dispose()
    >>> myBtnLibEveDown=Nothing
    >>>
    >>> 'Texte de la Colonne Header : e.Item.Cells(1)
    >>> 'Label Colonne DATECH.
    >>> Dim myDatEch As New Label
    >>> With myDatEch
    >>> .Id="myDatEch"
    >>>
    >>> .Text=myLocalization.EasyResourceManager.myGetString("myDatEch","patent.aspx")
    >>> .EnableViewState = ctype("False",Boolean)
    >>> .CssClass="txtOres2"
    >>> .Attributes.Add("runat", "server")
    >>> End With
    >>>
    >>> 'Ajout Control ImageButton UP DATECH.
    >>> Dim myBtnDatEchUp As New ImageButton
    >>> With myBtnDatEchUp
    >>> .ImageUrl="/img/gen/up.gif"
    >>> .EnableViewState = ctype("False",Boolean)
    >>> .CausesValidation=ctype("False",Boolean)
    >>> .Attributes.Add("runat", "server")
    >>> .Attributes.Add("onMouseOver", "window.status=' '; return
    >>> true;")
    >>>
    >>> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveUp","patent.aspx")
    >>> .Id="myBtnDatEchUp"
    >>> .CommandArgument="DATECH ASC"
    >>> AddHandler myBtnDatEchUp.Command, New
    >>> CommandEventHandler(AddressOf
    >>> myImgButtonSorting)
    >>> End With
    >>>
    >>> 'Ajout Control ImageButton DOWN DATECH.
    >>> Dim myBtnDatEchDown As New ImageButton
    >>> With myBtnDatEchDown
    >>> .ImageUrl="/img/gen/down.gif"
    >>> .EnableViewState = ctype("False",Boolean)
    >>> .CausesValidation=ctype("False",Boolean)
    >>> .Attributes.Add("runat", "server")
    >>> .Attributes.Add("onMouseOver", "window.status=' '; return
    >>> true;")
    >>>
    >>> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveDown","patent.aspx")
    >>> .Id="myBtnDatEchDown"
    >>> .CommandArgument="DATECH DESC"
    >>> AddHandler myBtnDatEchDown.Command, New
    >>> CommandEventHandler(AddressOf
    >>> myImgButtonSorting)
    >>> End With
    >>>
    >>> 'Ajout Effectif dans e.Item.Cells(0)
    >>> e.Item.Cells(1).Controls.Add(myDatEch)
    >>> e.Item.Cells(1).Controls.Add(myBtnDatEchUp)
    >>> e.Item.Cells(1).Controls.Add(myBtnDatEchDown)
    >>>
    >>> 'Libération Mémoire des trois Controls
    >>> myDatEch.Dispose()
    >>> myDatEch=Nothing
    >>> myBtnDatEchUp.Dispose()
    >>> myBtnDatEchUp=Nothing
    >>> myBtnDatEchDown.Dispose()
    >>> myBtnDatEchDown=Nothing
    >>>
    >>> 'Texte de la Colonne Header : e.Item.Cells(2)
    >>> 'Label Colonne NATURE.
    >>> Dim myNature As New Label
    >>> With myNature
    >>> .Id="myNature"
    >>>
    >>> .Text=myLocalization.EasyResourceManager.myGetString("myNature","patent.aspx")
    >>> .EnableViewState = ctype("False",Boolean)
    >>> .CssClass="txtOres2"
    >>> .Attributes.Add("runat", "server")
    >>> End With
    >>>
    >>> 'Ajout Effectif dans e.Item.Cells(0)
    >>> e.Item.Cells(2).Controls.Add(myNature)
    >>>
    >>> 'Libération Mémoire des trois Controls
    >>> myNature.Dispose()
    >>> myNature=Nothing
    >>>
    >>> End If '.Item.ItemType = ListItemType.Header
    >>>
    >>> End Sub 'my009DataGrid_ItemCreated
    >>>
    >>>
    >>> part 2/ In .aspx file : My datagrid with OnItemCreated parameter
    >>>
    >>> <asp:DataGrid id="my009DataGrid"
    >>> runat="server"
    >>> FooterStyle-BorderWidth="0"
    >>> ShowFooter="False"
    >>> FooterStyle-BackColor="#F29168"
    >>> FooterStyle-ForeColor="#FFFFFF"
    >>> FooterStyle-BorderStyle= "None"
    >>> PagerStyle-Mode="NumericPages"
    >>> PageCount="1"
    >>> AutoGenerateColumns="False"
    >>> borderwidth="1"
    >>> bordercolor="black"
    >>> BorderStyle="Solid"
    >>> PagerStyle-VerticalAlign="top"
    >>> Cellpadding="1"
    >>> Cellspacing="0"
    >>> ShowHeader="True"
    >>> HeaderStyle-ForeColor="White"
    >>> HeaderStyle-Font-Bold="False"
    >>> HeaderStyle-HorizontalAlign="Center"
    >>> HeaderStyle-VerticalAlign="Middle"
    >>> AllowSorting="False"
    >>> AllowPaging="True"
    >>> OnPageIndexChanged="PageIndexChanged_OnClick"
    >>> OnItemCreated="my009DataGrid_ItemCreated"
    >>> PageSize="5"
    >>> width="100%"
    >>> HeaderStyle-BackColor="#93b0cc"
    >>> BackColor="#e5ecf2"
    >>> AlternatingItemStyle-BackColor="#e5ecf2"
    >>> PagerStyle-Backcolor="#93b0cc"
    >>> PagerStyle-Forecolor="Black"
    >>> PagerStyle-HorizontalAlign="Right"
    >>> PagerStyle-BorderStyle="Inset">
    >>>
    >>> <Columns>
    >>> <asp:BoundColumn DataField="libeve" ReadOnly="true">
    >>> <ItemStyle Font-Names="Times New Roman, Times, serif"
    >>> ForeColor="#003B6F"
    >>> Font-Size="10" horizontalalign="Left" VerticalAlign="Middle"
    >>> width="40%">
    >>> </ItemStyle>
    >>> </asp:BoundColumn>
    >>>
    >>> <asp:BoundColumn DataField="datech" DataFormatString="{0:d}"
    >>> ReadOnly="true">
    >>> <ItemStyle Font-Names="Times New Roman, Times, serif"
    >>> ForeColor="#003B6F"
    >>> Font-Size="10" horizontalalign="Center" VerticalAlign="Middle"
    >>> width="30%">
    >>> </ItemStyle>
    >>> </asp:BoundColumn>
    >>>
    >>> <asp:BoundColumn DataField="nature" ReadOnly="true"
    >>> HeaderText="Nature">
    >>> <ItemStyle Font-Names="Times New Roman, Times, serif"
    >>> ForeColor="#003B6F"
    >>> Font-Size="10" horizontalalign="Center" VerticalAlign="Middle"
    >>> width="30%">
    >>> </ItemStyle>
    >>> </asp:BoundColumn>
    >>> </Columns>
    >>>
    >>> </asp:DataGrid>
    >>>
    >>>
    >>>
    >>> thanks for your help

    >>
    >> I wonder why you are doing the dispose of the controls you create, I
    >> would
    >> think that one of the things that a dispose would do is remove all
    >> handlers.
    >>
    >> Hope this helps
    >> LS

    >


    Don't take this a gospel but it looks like in 1.1 the dispose did not remove
    the handler. That is only conjecture but I am glad that fixed the problem.

    LS
     
    Lloyd Sheen, Jun 25, 2009
    #6
  7. Fabrice

    kaushik Guest

    Re: More about my code : Problem with AddHandler (New CommandEventHandler) under framework 2.0

    thanks

    "Lloyd Sheen" <> wrote in message
    news:...
    >
    > "Fabrice" <> wrote in message
    > news:...
    >> Hello Lloyd
    >>
    >> Your are right. I removed the "dispose" of the controls I have created.
    >> And It works. I don't understand the difference of behavior between
    >> framework 1.1 and 2.0.
    >>
    >> If your can explain me.
    >>
    >> Thanks
    >> fabrice
    >>
    >>> think that one of the things that a dispose would do is remove all
    >>> handlers.

    >>
    >> Lloyd Sheen wrote:
    >>
    >>>
    >>> "Fabrice" <> wrote in message
    >>> news:us%...
    >>>> Sorry. This is my code :
    >>>>
    >>>> In my aspx file, I have a datagrid with the "OnItemCreated" parameter.
    >>>> In my code behind (VB file), I have built all the buttons by code
    >>>> (ImageButton).
    >>>>
    >>>> The Handler on the differents ImageButtons seems not be fire under .net
    >>>> 2.0
    >>>> It is ok under 1.1
    >>>>
    >>>> In my datagrid The parameter OnItemCreated is
    >>>> OnItemCreated="my009DataGrid_ItemCreated"
    >>>> (see part 2)
    >>>>
    >>>> part 1/ My code file in my .vb file
    >>>> ------------------------------------
    >>>>
    >>>>
    >>>> Sub my009DataGrid_ItemCreated(ByVal sender As Object, ByVal e As
    >>>> System.Web.UI.WebControls.DataGridItemEventArgs)
    >>>>
    >>>> If e.Item.ItemType = ListItemType.Header Then
    >>>>
    >>>> 'ImageButton Header column : e.Item.Cells(0)
    >>>>
    >>>> Dim myLibEve As New Label
    >>>> With myLibEve
    >>>> .Id="myLibEve"
    >>>>
    >>>> .Text=myLocalization.EasyResourceManager.myGetString("myLibEve","patent.aspx")
    >>>> .EnableViewState = ctype("False",Boolean)
    >>>> .CssClass="txtOres2"
    >>>> .Attributes.Add("runat", "server")
    >>>> End With
    >>>>
    >>>> 'ADD Control ImageButton UP LIBEVE.
    >>>> Dim myBtnLibEveUp As New ImageButton
    >>>> With myBtnLibEveUp
    >>>> .ImageUrl="/img/gen/up.gif"
    >>>> .EnableViewState = ctype("False",Boolean)
    >>>> .CausesValidation=ctype("False",Boolean)
    >>>> .Attributes.Add("runat", "server")
    >>>> .Attributes.Add("onMouseOver", "window.status=' '; return true;")
    >>>>
    >>>> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveUp","patent.aspx")
    >>>> .Id="myBtnLibEveUp"
    >>>> .CommandArgument="LIBEVE ASC"
    >>>> AddHandler myBtnLibEveUp.Command, New CommandEventHandler(AddressOf
    >>>> myImgButtonSorting)
    >>>> End With
    >>>>
    >>>> 'ADD Control ImageButton DOWN LIBEVE.
    >>>> Dim myBtnLibEveDown As New ImageButton
    >>>> With myBtnLibEveDown
    >>>> .ImageUrl="/img/gen/down.gif"
    >>>> .EnableViewState = ctype("False",Boolean)
    >>>> .CausesValidation=ctype("False",Boolean)
    >>>> .Attributes.Add("runat", "server")
    >>>> .Attributes.Add("onMouseOver", "window.status=' '; return true;")
    >>>> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveDown","patent.aspx")
    >>>> .Id="myBtnLibEveDown"
    >>>> .CommandArgument="LIBEVE DESC"
    >>>> AddHandler myBtnLibEveDown.Command, New CommandEventHandler(AddressOf
    >>>> myImgButtonSorting)
    >>>> End With
    >>>>
    >>>> 'Add controls in e.Item.Cells(0)
    >>>> e.Item.Cells(0).Controls.Add(myLibEve)
    >>>> e.Item.Cells(0).Controls.Add(myBtnLibEveUp)
    >>>> e.Item.Cells(0).Controls.Add(myBtnLibEveDown)
    >>>>
    >>>>
    >>>> myLibEve.Dispose()
    >>>> myLibEve=Nothing
    >>>> myBtnLibEveUp.Dispose()
    >>>> myBtnLibEveUp=Nothing
    >>>> myBtnLibEveDown.Dispose()
    >>>> myBtnLibEveDown=Nothing
    >>>>
    >>>> 'Texte de la Colonne Header : e.Item.Cells(1)
    >>>> 'Label Colonne DATECH.
    >>>> Dim myDatEch As New Label
    >>>> With myDatEch
    >>>> .Id="myDatEch"
    >>>>
    >>>> .Text=myLocalization.EasyResourceManager.myGetString("myDatEch","patent.aspx")
    >>>> .EnableViewState = ctype("False",Boolean)
    >>>> .CssClass="txtOres2"
    >>>> .Attributes.Add("runat", "server")
    >>>> End With
    >>>>
    >>>> 'Ajout Control ImageButton UP DATECH.
    >>>> Dim myBtnDatEchUp As New ImageButton
    >>>> With myBtnDatEchUp
    >>>> .ImageUrl="/img/gen/up.gif"
    >>>> .EnableViewState = ctype("False",Boolean)
    >>>> .CausesValidation=ctype("False",Boolean)
    >>>> .Attributes.Add("runat", "server")
    >>>> .Attributes.Add("onMouseOver", "window.status=' ';
    >>>> return
    >>>> true;")
    >>>>
    >>>> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveUp","patent.aspx")
    >>>> .Id="myBtnDatEchUp"
    >>>> .CommandArgument="DATECH ASC"
    >>>> AddHandler myBtnDatEchUp.Command, New
    >>>> CommandEventHandler(AddressOf
    >>>> myImgButtonSorting)
    >>>> End With
    >>>>
    >>>> 'Ajout Control ImageButton DOWN DATECH.
    >>>> Dim myBtnDatEchDown As New ImageButton
    >>>> With myBtnDatEchDown
    >>>> .ImageUrl="/img/gen/down.gif"
    >>>> .EnableViewState = ctype("False",Boolean)
    >>>> .CausesValidation=ctype("False",Boolean)
    >>>> .Attributes.Add("runat", "server")
    >>>> .Attributes.Add("onMouseOver", "window.status=' ';
    >>>> return
    >>>> true;")
    >>>>
    >>>> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveDown","patent.aspx")
    >>>> .Id="myBtnDatEchDown"
    >>>> .CommandArgument="DATECH DESC"
    >>>> AddHandler myBtnDatEchDown.Command, New
    >>>> CommandEventHandler(AddressOf
    >>>> myImgButtonSorting)
    >>>> End With
    >>>>
    >>>> 'Ajout Effectif dans e.Item.Cells(0)
    >>>> e.Item.Cells(1).Controls.Add(myDatEch)
    >>>> e.Item.Cells(1).Controls.Add(myBtnDatEchUp)
    >>>> e.Item.Cells(1).Controls.Add(myBtnDatEchDown)
    >>>>
    >>>> 'Libération Mémoire des trois Controls
    >>>> myDatEch.Dispose()
    >>>> myDatEch=Nothing
    >>>> myBtnDatEchUp.Dispose()
    >>>> myBtnDatEchUp=Nothing
    >>>> myBtnDatEchDown.Dispose()
    >>>> myBtnDatEchDown=Nothing
    >>>>
    >>>> 'Texte de la Colonne Header : e.Item.Cells(2)
    >>>> 'Label Colonne NATURE.
    >>>> Dim myNature As New Label
    >>>> With myNature
    >>>> .Id="myNature"
    >>>>
    >>>> .Text=myLocalization.EasyResourceManager.myGetString("myNature","patent.aspx")
    >>>> .EnableViewState = ctype("False",Boolean)
    >>>> .CssClass="txtOres2"
    >>>> .Attributes.Add("runat", "server")
    >>>> End With
    >>>>
    >>>> 'Ajout Effectif dans e.Item.Cells(0)
    >>>> e.Item.Cells(2).Controls.Add(myNature)
    >>>>
    >>>> 'Libération Mémoire des trois Controls
    >>>> myNature.Dispose()
    >>>> myNature=Nothing
    >>>>
    >>>> End If '.Item.ItemType = ListItemType.Header
    >>>>
    >>>> End Sub 'my009DataGrid_ItemCreated
    >>>>
    >>>>
    >>>> part 2/ In .aspx file : My datagrid with OnItemCreated parameter
    >>>>
    >>>> <asp:DataGrid id="my009DataGrid"
    >>>> runat="server"
    >>>> FooterStyle-BorderWidth="0"
    >>>> ShowFooter="False"
    >>>> FooterStyle-BackColor="#F29168"
    >>>> FooterStyle-ForeColor="#FFFFFF"
    >>>> FooterStyle-BorderStyle= "None"
    >>>> PagerStyle-Mode="NumericPages"
    >>>> PageCount="1"
    >>>> AutoGenerateColumns="False"
    >>>> borderwidth="1"
    >>>> bordercolor="black"
    >>>> BorderStyle="Solid"
    >>>> PagerStyle-VerticalAlign="top"
    >>>> Cellpadding="1"
    >>>> Cellspacing="0"
    >>>> ShowHeader="True"
    >>>> HeaderStyle-ForeColor="White"
    >>>> HeaderStyle-Font-Bold="False"
    >>>> HeaderStyle-HorizontalAlign="Center"
    >>>> HeaderStyle-VerticalAlign="Middle"
    >>>> AllowSorting="False"
    >>>> AllowPaging="True"
    >>>> OnPageIndexChanged="PageIndexChanged_OnClick"
    >>>> OnItemCreated="my009DataGrid_ItemCreated"
    >>>> PageSize="5"
    >>>> width="100%"
    >>>> HeaderStyle-BackColor="#93b0cc"
    >>>> BackColor="#e5ecf2"
    >>>> AlternatingItemStyle-BackColor="#e5ecf2"
    >>>> PagerStyle-Backcolor="#93b0cc"
    >>>> PagerStyle-Forecolor="Black"
    >>>> PagerStyle-HorizontalAlign="Right"
    >>>> PagerStyle-BorderStyle="Inset">
    >>>>
    >>>> <Columns>
    >>>> <asp:BoundColumn DataField="libeve" ReadOnly="true">
    >>>> <ItemStyle Font-Names="Times New Roman, Times, serif"
    >>>> ForeColor="#003B6F"
    >>>> Font-Size="10" horizontalalign="Left" VerticalAlign="Middle"
    >>>> width="40%">
    >>>> </ItemStyle>
    >>>> </asp:BoundColumn>
    >>>>
    >>>> <asp:BoundColumn DataField="datech" DataFormatString="{0:d}"
    >>>> ReadOnly="true">
    >>>> <ItemStyle Font-Names="Times New Roman, Times, serif"
    >>>> ForeColor="#003B6F"
    >>>> Font-Size="10" horizontalalign="Center" VerticalAlign="Middle"
    >>>> width="30%">
    >>>> </ItemStyle>
    >>>> </asp:BoundColumn>
    >>>>
    >>>> <asp:BoundColumn DataField="nature" ReadOnly="true"
    >>>> HeaderText="Nature">
    >>>> <ItemStyle Font-Names="Times New Roman, Times, serif"
    >>>> ForeColor="#003B6F"
    >>>> Font-Size="10" horizontalalign="Center" VerticalAlign="Middle"
    >>>> width="30%">
    >>>> </ItemStyle>
    >>>> </asp:BoundColumn>
    >>>> </Columns>
    >>>>
    >>>> </asp:DataGrid>
    >>>>
    >>>>
    >>>>
    >>>> thanks for your help
    >>>
    >>> I wonder why you are doing the dispose of the controls you create, I
    >>> would
    >>> think that one of the things that a dispose would do is remove all
    >>> handlers.
    >>>
    >>> Hope this helps
    >>> LS

    >>

    >
    > Don't take this a gospel but it looks like in 1.1 the dispose did not
    > remove the handler. That is only conjecture but I am glad that fixed the
    > problem.
    >
    > LS
     
    kaushik, Jun 26, 2009
    #7
  8. Fabrice

    Fabrice Guest

    Re: More about my code : Problem with AddHandler (New CommandEventHandler) under framework 2.0

    Sorry for my late,

    Thanks for your help.
    And have a nice week end.

    fabrice

    Lloyd Sheen wrote:

    >
    > "Fabrice" <> wrote in message
    > news:...
    >> Hello Lloyd
    >>
    >> Your are right. I removed the "dispose" of the controls I have created.
    >> And It works. I don't understand the difference of behavior between
    >> framework 1.1 and 2.0.
    >>
    >> If your can explain me.
    >>
    >> Thanks
    >> fabrice
    >>
    >>> think that one of the things that a dispose would do is remove all
    >>> handlers.

    >>
    >> Lloyd Sheen wrote:
    >>
    >>>
    >>> "Fabrice" <> wrote in message
    >>> news:us%...
    >>>> Sorry. This is my code :
    >>>>
    >>>> In my aspx file, I have a datagrid with the "OnItemCreated" parameter.
    >>>> In my code behind (VB file), I have built all the buttons by code
    >>>> (ImageButton).
    >>>>
    >>>> The Handler on the differents ImageButtons seems not be fire under .net
    >>>> 2.0
    >>>> It is ok under 1.1
    >>>>
    >>>> In my datagrid The parameter OnItemCreated is
    >>>> OnItemCreated="my009DataGrid_ItemCreated"
    >>>> (see part 2)
    >>>>
    >>>> part 1/ My code file in my .vb file
    >>>> ------------------------------------
    >>>>
    >>>>
    >>>> Sub my009DataGrid_ItemCreated(ByVal sender As Object, ByVal e As
    >>>> System.Web.UI.WebControls.DataGridItemEventArgs)
    >>>>
    >>>> If e.Item.ItemType = ListItemType.Header Then
    >>>>
    >>>> 'ImageButton Header column : e.Item.Cells(0)
    >>>>
    >>>> Dim myLibEve As New Label
    >>>> With myLibEve
    >>>> .Id="myLibEve"
    >>>>
    >>>> .Text=myLocalization.EasyResourceManager.myGetString("myLibEve","patent.aspx")
    >>>> .EnableViewState = ctype("False",Boolean)
    >>>> .CssClass="txtOres2"
    >>>> .Attributes.Add("runat", "server")
    >>>> End With
    >>>>
    >>>> 'ADD Control ImageButton UP LIBEVE.
    >>>> Dim myBtnLibEveUp As New ImageButton
    >>>> With myBtnLibEveUp
    >>>> .ImageUrl="/img/gen/up.gif"
    >>>> .EnableViewState = ctype("False",Boolean)
    >>>> .CausesValidation=ctype("False",Boolean)
    >>>> .Attributes.Add("runat", "server")
    >>>> .Attributes.Add("onMouseOver", "window.status=' '; return true;")
    >>>>
    >>>> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveUp","patent.aspx")
    >>>> .Id="myBtnLibEveUp"
    >>>> .CommandArgument="LIBEVE ASC"
    >>>> AddHandler myBtnLibEveUp.Command, New CommandEventHandler(AddressOf
    >>>> myImgButtonSorting)
    >>>> End With
    >>>>
    >>>> 'ADD Control ImageButton DOWN LIBEVE.
    >>>> Dim myBtnLibEveDown As New ImageButton
    >>>> With myBtnLibEveDown
    >>>> .ImageUrl="/img/gen/down.gif"
    >>>> .EnableViewState = ctype("False",Boolean)
    >>>> .CausesValidation=ctype("False",Boolean)
    >>>> .Attributes.Add("runat", "server")
    >>>> .Attributes.Add("onMouseOver", "window.status=' '; return true;")
    >>>> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveDown","patent.aspx")
    >>>> .Id="myBtnLibEveDown"
    >>>> .CommandArgument="LIBEVE DESC"
    >>>> AddHandler myBtnLibEveDown.Command, New CommandEventHandler(AddressOf
    >>>> myImgButtonSorting)
    >>>> End With
    >>>>
    >>>> 'Add controls in e.Item.Cells(0)
    >>>> e.Item.Cells(0).Controls.Add(myLibEve)
    >>>> e.Item.Cells(0).Controls.Add(myBtnLibEveUp)
    >>>> e.Item.Cells(0).Controls.Add(myBtnLibEveDown)
    >>>>
    >>>>
    >>>> myLibEve.Dispose()
    >>>> myLibEve=Nothing
    >>>> myBtnLibEveUp.Dispose()
    >>>> myBtnLibEveUp=Nothing
    >>>> myBtnLibEveDown.Dispose()
    >>>> myBtnLibEveDown=Nothing
    >>>>
    >>>> 'Texte de la Colonne Header : e.Item.Cells(1)
    >>>> 'Label Colonne DATECH.
    >>>> Dim myDatEch As New Label
    >>>> With myDatEch
    >>>> .Id="myDatEch"
    >>>>
    >>>> .Text=myLocalization.EasyResourceManager.myGetString("myDatEch","patent.aspx")
    >>>> .EnableViewState = ctype("False",Boolean)
    >>>> .CssClass="txtOres2"
    >>>> .Attributes.Add("runat", "server")
    >>>> End With
    >>>>
    >>>> 'Ajout Control ImageButton UP DATECH.
    >>>> Dim myBtnDatEchUp As New ImageButton
    >>>> With myBtnDatEchUp
    >>>> .ImageUrl="/img/gen/up.gif"
    >>>> .EnableViewState = ctype("False",Boolean)
    >>>> .CausesValidation=ctype("False",Boolean)
    >>>> .Attributes.Add("runat", "server")
    >>>> .Attributes.Add("onMouseOver", "window.status=' ';
    >>>> return
    >>>> true;")
    >>>>
    >>>> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveUp","patent.aspx")
    >>>> .Id="myBtnDatEchUp"
    >>>> .CommandArgument="DATECH ASC"
    >>>> AddHandler myBtnDatEchUp.Command, New
    >>>> CommandEventHandler(AddressOf
    >>>> myImgButtonSorting)
    >>>> End With
    >>>>
    >>>> 'Ajout Control ImageButton DOWN DATECH.
    >>>> Dim myBtnDatEchDown As New ImageButton
    >>>> With myBtnDatEchDown
    >>>> .ImageUrl="/img/gen/down.gif"
    >>>> .EnableViewState = ctype("False",Boolean)
    >>>> .CausesValidation=ctype("False",Boolean)
    >>>> .Attributes.Add("runat", "server")
    >>>> .Attributes.Add("onMouseOver", "window.status=' ';
    >>>> return
    >>>> true;")
    >>>>
    >>>> .AlternateText=myLocalization.EasyResourceManager.myGetString("BtnLibEveDown","patent.aspx")
    >>>> .Id="myBtnDatEchDown"
    >>>> .CommandArgument="DATECH DESC"
    >>>> AddHandler myBtnDatEchDown.Command, New
    >>>> CommandEventHandler(AddressOf
    >>>> myImgButtonSorting)
    >>>> End With
    >>>>
    >>>> 'Ajout Effectif dans e.Item.Cells(0)
    >>>> e.Item.Cells(1).Controls.Add(myDatEch)
    >>>> e.Item.Cells(1).Controls.Add(myBtnDatEchUp)
    >>>> e.Item.Cells(1).Controls.Add(myBtnDatEchDown)
    >>>>
    >>>> 'Libération Mémoire des trois Controls
    >>>> myDatEch.Dispose()
    >>>> myDatEch=Nothing
    >>>> myBtnDatEchUp.Dispose()
    >>>> myBtnDatEchUp=Nothing
    >>>> myBtnDatEchDown.Dispose()
    >>>> myBtnDatEchDown=Nothing
    >>>>
    >>>> 'Texte de la Colonne Header : e.Item.Cells(2)
    >>>> 'Label Colonne NATURE.
    >>>> Dim myNature As New Label
    >>>> With myNature
    >>>> .Id="myNature"
    >>>>
    >>>> .Text=myLocalization.EasyResourceManager.myGetString("myNature","patent.aspx")
    >>>> .EnableViewState = ctype("False",Boolean)
    >>>> .CssClass="txtOres2"
    >>>> .Attributes.Add("runat", "server")
    >>>> End With
    >>>>
    >>>> 'Ajout Effectif dans e.Item.Cells(0)
    >>>> e.Item.Cells(2).Controls.Add(myNature)
    >>>>
    >>>> 'Libération Mémoire des trois Controls
    >>>> myNature.Dispose()
    >>>> myNature=Nothing
    >>>>
    >>>> End If '.Item.ItemType = ListItemType.Header
    >>>>
    >>>> End Sub 'my009DataGrid_ItemCreated
    >>>>
    >>>>
    >>>> part 2/ In .aspx file : My datagrid with OnItemCreated parameter
    >>>>
    >>>> <asp:DataGrid id="my009DataGrid"
    >>>> runat="server"
    >>>> FooterStyle-BorderWidth="0"
    >>>> ShowFooter="False"
    >>>> FooterStyle-BackColor="#F29168"
    >>>> FooterStyle-ForeColor="#FFFFFF"
    >>>> FooterStyle-BorderStyle= "None"
    >>>> PagerStyle-Mode="NumericPages"
    >>>> PageCount="1"
    >>>> AutoGenerateColumns="False"
    >>>> borderwidth="1"
    >>>> bordercolor="black"
    >>>> BorderStyle="Solid"
    >>>> PagerStyle-VerticalAlign="top"
    >>>> Cellpadding="1"
    >>>> Cellspacing="0"
    >>>> ShowHeader="True"
    >>>> HeaderStyle-ForeColor="White"
    >>>> HeaderStyle-Font-Bold="False"
    >>>> HeaderStyle-HorizontalAlign="Center"
    >>>> HeaderStyle-VerticalAlign="Middle"
    >>>> AllowSorting="False"
    >>>> AllowPaging="True"
    >>>> OnPageIndexChanged="PageIndexChanged_OnClick"
    >>>> OnItemCreated="my009DataGrid_ItemCreated"
    >>>> PageSize="5"
    >>>> width="100%"
    >>>> HeaderStyle-BackColor="#93b0cc"
    >>>> BackColor="#e5ecf2"
    >>>> AlternatingItemStyle-BackColor="#e5ecf2"
    >>>> PagerStyle-Backcolor="#93b0cc"
    >>>> PagerStyle-Forecolor="Black"
    >>>> PagerStyle-HorizontalAlign="Right"
    >>>> PagerStyle-BorderStyle="Inset">
    >>>>
    >>>> <Columns>
    >>>> <asp:BoundColumn DataField="libeve" ReadOnly="true">
    >>>> <ItemStyle Font-Names="Times New Roman, Times, serif"
    >>>> ForeColor="#003B6F"
    >>>> Font-Size="10" horizontalalign="Left" VerticalAlign="Middle"
    >>>> width="40%">
    >>>> </ItemStyle>
    >>>> </asp:BoundColumn>
    >>>>
    >>>> <asp:BoundColumn DataField="datech" DataFormatString="{0:d}"
    >>>> ReadOnly="true">
    >>>> <ItemStyle Font-Names="Times New Roman, Times, serif"
    >>>> ForeColor="#003B6F"
    >>>> Font-Size="10" horizontalalign="Center" VerticalAlign="Middle"
    >>>> width="30%">
    >>>> </ItemStyle>
    >>>> </asp:BoundColumn>
    >>>>
    >>>> <asp:BoundColumn DataField="nature" ReadOnly="true"
    >>>> HeaderText="Nature">
    >>>> <ItemStyle Font-Names="Times New Roman, Times, serif"
    >>>> ForeColor="#003B6F"
    >>>> Font-Size="10" horizontalalign="Center" VerticalAlign="Middle"
    >>>> width="30%">
    >>>> </ItemStyle>
    >>>> </asp:BoundColumn>
    >>>> </Columns>
    >>>>
    >>>> </asp:DataGrid>
    >>>>
    >>>>
    >>>>
    >>>> thanks for your help
    >>>
    >>> I wonder why you are doing the dispose of the controls you create, I
    >>> would
    >>> think that one of the things that a dispose would do is remove all
    >>> handlers.
    >>>
    >>> Hope this helps
    >>> LS

    >>

    >
    > Don't take this a gospel but it looks like in 1.1 the dispose did not
    > remove
    > the handler. That is only conjecture but I am glad that fixed the
    > problem.
    >
    > LS
     
    Fabrice, Jun 27, 2009
    #8
    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. Nathan Sokalski
    Replies:
    3
    Views:
    3,067
    Nathan Sokalski
    Jun 9, 2005
  2. Shapper
    Replies:
    1
    Views:
    400
    Shapper
    Oct 29, 2005
  3. =?Utf-8?B?REo=?=

    AddHandler Problem

    =?Utf-8?B?REo=?=, Nov 1, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    3,117
    Ben Amada
    Nov 2, 2005
  4. DC
    Replies:
    2
    Views:
    401
  5. haile
    Replies:
    1
    Views:
    495
    haile
    Nov 24, 2004
Loading...

Share This Page