This is a migrated thread and some comments may be shown as answers.

Add event handler to control in template column

1 Answer 263 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steven Black
Top achievements
Rank 1
Steven Black asked on 19 Aug 2009, 09:06 PM
I am creating a grid dynamically within the Page_Init event.  Within my grid I have a GridTemplateColumn that has a Textbox in it.  In order to do this I created a GridTemplateColumn_TextBox class.

I want to add an event handler to the TextChanged event.  I can do this from within my GridTemplateColumn_Textbox class and everything works fine (ie. AddHandler txtBox.TextChanged, AddressOf txtBox_TextChanged)

The problem is that I don't want to add it from within my class, because I want my class to be a very generic class that I can use whenever I want to add this particular GridTemplateColumn to a grid, but the particular event handler in question is very specific to one particular page.

Is there a way to get a reference to the Textbox within my GridTemplateColumn and add my event handler from within my page itself instead of the class?

Hopefully I'm clear as to what I'm trying to do.  If not, please let me know.

Thanks.

Steve

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 19 Aug 2009, 09:43 PM
Hello Steven,

You can attach the event handler on ItemCreated event.
Protected Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As GridItemEventArgs) Handles RadGrid1.ItemCreated 
    If TypeOf e.Item Is GridDataItem Then 
        Dim tb As TextBox = TryCast(e.Item.FindControl("TextBox1"), TextBox) 
        tb.AutoPostBack = True 
        AddHandler tb.TextChanged, AddressOf tb_TextChanged 
    End If 
End Sub 
 
Private Sub tb_TextChanged(ByVal sender As ObjectByVal e As EventArgs) 
    'do something 
End Sub 

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Steven Black
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or