This is a migrated thread and some comments may be shown as answers.

ASP.NET Reference dynamically created control back in server aspx.cs server code

1 Answer 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 2
George asked on 14 Mar 2015, 05:20 AM
And my endless problems from server created controls continue.

I have users that are in different groups and each group has different user information. I am creating a page to manage users in a group using a Telerik RadGrid. Because of the unknown nature of the grid columns I am creating the grid on completely on the server.  You cannot have a grid defined in the aspx page and add columns in the server aspx.cs code, all kinds of things break like sorting, filters and extra text added.  The grid works fine.  

A feature I need is to output excel files with the grid's data. The problem, how do I reference the grid in server calls backs. If you look at Grid Export To Excel there is a button callback that changes grid values on the server and initiates the excel export on the grid control in ImageButton_Click.  In my case RadGrid1 is created in the server in the Page_Init and added to an asp:PlaceHolder. 

Is there any way to reference a server added control back in the server aspx.cs code.  Putting the control id will not compile.

I am going to want deal with Row Selected values which will also need server intervention dealing with the selected rows.

Thanks,
George

1 Answer, 1 is accepted

Sort by
0
George
Top achievements
Rank 2
answered on 16 Mar 2015, 04:51 PM
The answer.

Assuming the grid is created and added in Page_Init(), the following can be done in a callback to reference the grid

RadGrid grid = PlaceHolder1.FindControl("grid") as RadGrid;

I found this in the answer to another question.
Tags
Grid
Asked by
George
Top achievements
Rank 2
Answers by
George
Top achievements
Rank 2
Share this question
or