Home All Groups Group Topic Archive Search About

Problem with AddHandler (New CommandEventHandler) under framework 2.0

Author
25 Jun 2009 3:47 PM
Fabrice
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

Author
25 Jun 2009 3:52 PM
Lloyd Sheen
Show quote Hide quote
"Fabrice" <emouchet@spaminfonietest.fr> wrote in message
news:uZyv9wa9JHA.4560@TK2MSFTNGP03.phx.gbl...
> 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
Are all your drivers up to date? click for free checkup

Author
25 Jun 2009 6:12 PM
Fabrice
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
Author
25 Jun 2009 7:51 PM
Lloyd Sheen
Show quote Hide quote
"Fabrice" <fabrice***@yahoo.text.fr> wrote in message
news:us%23Q6Bc9JHA.5040@TK2MSFTNGP04.phx.gbl...
> 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
Author
25 Jun 2009 8:35 PM
Fabrice
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:

Show quoteHide quote
>
> "Fabrice" <fabrice***@yahoo.text.fr> wrote in message
> news:us%23Q6Bc9JHA.5040@TK2MSFTNGP04.phx.gbl...
>> 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
Author
25 Jun 2009 9:12 PM
Lloyd Sheen
Show quote Hide quote
"Fabrice" <fabrice***@yahoo.text.fr> wrote in message
news:ecLzsRd9JHA.4204@TK2MSFTNGP04.phx.gbl...
> 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" <fabrice***@yahoo.text.fr> wrote in message
>> news:us%23Q6Bc9JHA.5040@TK2MSFTNGP04.phx.gbl...
>>> 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
Author
26 Jun 2009 5:22 AM
kaushik
thanks

Show quoteHide quote
"Lloyd Sheen" <a@b.c> wrote in message
news:erRXfmd9JHA.1488@TK2MSFTNGP03.phx.gbl...
>
> "Fabrice" <fabrice***@yahoo.text.fr> wrote in message
> news:ecLzsRd9JHA.4204@TK2MSFTNGP04.phx.gbl...
>> 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" <fabrice***@yahoo.text.fr> wrote in message
>>> news:us%23Q6Bc9JHA.5040@TK2MSFTNGP04.phx.gbl...
>>>> 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
Author
27 Jun 2009 12:26 PM
Fabrice
Sorry for my late,

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

fabrice

Lloyd Sheen wrote:

Show quoteHide quote
>
> "Fabrice" <fabrice***@yahoo.text.fr> wrote in message
> news:ecLzsRd9JHA.4204@TK2MSFTNGP04.phx.gbl...
>> 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" <fabrice***@yahoo.text.fr> wrote in message
>>> news:us%23Q6Bc9JHA.5040@TK2MSFTNGP04.phx.gbl...
>>>> 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

Bookmark and Share