Solved

How to Find a Control in the footer of a repeater

Posted on 2006-11-17
3
509 Views
Last Modified: 2012-08-14
I need to access a button control that is located in the footer of a repeater.  Currently I've tried this, which returned an "Object not set to..." error.

Sub someSub()
  CType(myRepeater.FindControl("myButton"), Button).Text = "New Text"
End Sub

Is this actually possible to do from outside the RepeaterItemEventArgs sub?
0
Comment
Question by:Rouchie
3 Comments
 
LVL 3

Accepted Solution

by:
viveksg earned 300 total points
ID: 17963713

You cannot get the footer item as such outside the reapeteritemeventargs since the header, footer, and separator are not included in the item collection.

So you have to declare a repeateritem variable, assign the footer item to this variable (in itemdatabound) and then use it.

e.g: in C#.

RepeaterItem rpItem;

private void rpItem_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
   if (e.Item.ItemType == ListItemType.Footer)
          rpItem = e.Item;
}

Sub someSub()
  CType(rpItem.FindControl("myButton"), Button).Text = "New Text"
End Sub

0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 100 total points
ID: 17964551
There is a way, using a recursive function, to use FindControl to find a control by ID anywhere in the hierarchy.

Bob
0
 
LVL 33

Assisted Solution

by:raterus
raterus earned 100 total points
ID: 17968259
If you save the UniqueID of the button, say in the viewstate, when the page posts back, you can use Page.FindControl("Controls_Unique_ID") to get a direct reference to it.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question