I've customized a Table subclass in my ASP.NET project that generates tables. This table utilizes a RowCreator class to format and create TableRows and TableCells, which are then called by MyTable. When MyTable calls rowCreator.CreateRow(), it receives a TableRow with various features included.
Within this TableRow is a TextBox that should trigger a javascript method on the onblur event, added by the RowCreator class.
textBox.Attributes.Add("onblur", "javascriptMethod('" + textbox.ClientID + "');");
I also attempted to create a subclass of textBox that implements a method for adding the onblur event:
Attributes.Add("onblur", "javascriptMethod('" + this + "');")
This approach did not work as expected, as the ID turned out to be just the namespace of the textbox subclass.
The JavaScript method itself is quite straightforward:
function javascriptMethod(boxId) {
alert(boxId);
}
The issue here is most likely due to the fact that the textbox control has not yet been added to the control collection, resulting in boxId being equivalent to the server-side ID instead of the client ID. Is there a way to obtain the correct ID without needing to add the row using Controls.Add on the page beforehand? Any alternate suggestions?
The reason behind all of this effort is to retrieve the contents of the textbox from a javascript function whenever changes are made. Perhaps there's a more effective approach to achieving this desired functionality?