trying to find the html id of a textbox in FooterTemplate at runtime

  • Thread starter Thread starter David C
  • Start date Start date
D

David C

Here is my goal. I have a textbox in the FooterTemplate of a datagrid

<FooterTemplate>
<asp:TextBox ID="txtFooterTextBox" Runat="server"></asp:TextBox>
</FooterTemplate>

When the html is created, in my case, it creates an html tag like this.

<input name="userLiabilities:dgFinancials:_ctl9:txtFooterTextBox"
type="text" id="userLiabilities_dgFinancials__ctl9_txtFooterTextBox" />

I need to get that id userLiabilities_dgFinancials__ctl9_txtFooterTextBox AT
RUNTIME. How can I do that? I see can tell that the nomenclature consists
of the user control id, the id of the datagrid, the id of the textbox and
"__ctl9_" to assign uniqueness to the textbox (although because it is in the
footer, not in Item, txtFooterTextBox is already guaranteed to be unique).

I need to some how find that so that I can dynamically create javascript
code. So perhaps in the event handler for ItemCreated,

if (e.Item.ItemType == ListItemType.Footer)
{
//looking for the html unique ID
TextBox txtFooterTextBox = (TextBox)e.Item.FindControl("txtFooterTextBox");

//here I need to get the ID
userLiabilities_dgFinancials__ctl9_txtFooterTextBox
}
 
Tried it in the event handler for ItemCreated

The ClientID is txtFooterTextBox, not
userLiabilities_dgFinancials__ctl9_txtFooterTextBox . I should have said so
in my posting. I also tried UniqueID, but it's still set to
txtFooterTextBox.

Thanks.
 
I am not sure if ItemCreated event is good for you. Try to do the same in
ItemDataBound, or, maybe, in preRender event.

Property ClientID is designed specially for getting control id as it is set
on client.

Eliyahu
 
Back
Top