Raising BubleEvents

R

Robert Brinson

I have created a custom TextBox by inheriting TextBox. My purpose in
this was so that I could raise a BubleEvent such that custom TextBoxes
that are child controls of a DataGrid would actually cause the
DataGrid's ItemCommand to be fired. Then I would know which row the
particular TextBox was in. Everything seems to work correctly.
However, when I get to the point that I do a FindControl on my
DataGrid object, I get a reference not set to an instance of an object
error. I have not messed with event manipulation at this level before.
So, I'm pretty certain I just doing something wrong. Does anyone know
how I could make certain that my event arguments includes the proper
datagrid item? Thanks in advance for any help that can be offered.
Below is the relevant code.

Public Class GridTextBox
Inherits System.Web.UI.WebControls.TextBox

Protected Event Command As DataGridCommandEventHandler

Protected Overridable Sub OnCommand(ByVal e As CommandEventArgs)
Dim handler As CommandEventHandler = CType(Events(e),
CommandEventHandler)
If Not (handler Is Nothing) Then
handler(Me, e)
End If

RaiseBubbleEvent(Me, e)
End Sub

Protected Overrides Sub OnTextChanged(ByVal e As EventArgs)
MyBase.OnTextChanged(e)
OnCommand(New CommandEventArgs("EditNotes", "Notes"))
End Sub
End Class


*******From CodeBehind Page:

Public Sub dgDetails_ItemCommand(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs) Handles dgDetails.ItemCommand
Select Case e.CommandName.ToString()
' This was done just to test if it was actually working...
Case "EditNotes"
Dim strTest As String
strTest = "notes"
CType(dgDetails.FindControl("txtNotesTab2"),
GridTextBox).Text() = strTest
End Select
End Sub


*******From ASPX Page:

<%@ Register TagPrefix="Custom" Namespace="ShopOrderTool" Assembly =
"ShopOrderTool" %>
..
..
..
</asp:datagrid><asp:datagrid id="dgDetails" Runat="server"
Width="100%" Visible="False" CellPadding="1"
AutoGenerateColumns="False" OnItemCommand="dgDetails_ItemCommand">
<ItemStyle Font-Size="XX-Small" Font-Names="Tahoma"></ItemStyle>
<HeaderStyle Font-Size="XX-Small" Font-Names="Tahoma"
Font-Bold="True" HorizontalAlign="Center" ForeColor="#DADEFE"
BackColor="#006699"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<ItemStyle></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtSeqTab2" Runat="server"
Font-Names="Tahoma" Font-Size="XX-Small" Width="35"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="OCDTE"></asp:BoundColumn>
<asp:BoundColumn DataField="OWRKC"></asp:BoundColumn>
<asp:BoundColumn DataField="OORD"></asp:BoundColumn>
<asp:BoundColumn DataField="OOPNO"></asp:BoundColumn>
<asp:BoundColumn DataField="OOPDS"></asp:BoundColumn>
<asp:BoundColumn DataField="Quantity"></asp:BoundColumn>
<asp:BoundColumn DataField="PostQty"></asp:BoundColumn>
<asp:BoundColumn DataField="ODPRD"></asp:BoundColumn>
<asp:BoundColumn DataField="OMAC"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemStyle></ItemStyle>
<ItemTemplate>
<Custom:GridTextBox id="txtNotesTab2" Runat="server"
Font-Names="Tahoma" Font-Size="XX-Small" Width="160"
AutoPostBack="True"></Custom:GridTextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn Visible="False"></asp:BoundColumn>
<asp:BoundColumn Visible="False"></asp:BoundColumn>
<asp:BoundColumn Visible="False"></asp:BoundColumn>
<asp:BoundColumn DataField="OCRIT"
Visible="False"></asp:BoundColumn>
<asp:BoundColumn DataField="Notes"
Visible="False"></asp:BoundColumn>
</Columns>
</asp:datagrid>


Robert Brinson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top