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

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
}
 
D

David C

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.
 
E

Eliyahu Goldin

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
 

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,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top