Solved

How to Find a Control in the footer of a repeater

Posted on 2006-11-17
3
507 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.

831 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