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

Creating UI Elements in Code-behind and specifying an event handler?

2 Answers 108 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 04 Aug 2011, 08:07 PM
I'm relatively new to Telerik, ASP.NET and VB so please bear with me.

I'm trying to build an admin page which will allow the user to change various properties drawn from a database.  I've got it working fine as far as getting/setting values to textboxes and now I'm trying to substitute in more specific UI elements such as color pickers and numeric text boxes.

As it stands the admin page uses a control, each control containing some table markup and a Placeholder element.  My thought was that I could attach correct UI widget based on the type of the control, but I can't get this to work.

In Page_Prerender of the control, the widgets are created and attached to the placeholder.  My problem comes in getting the changed values from these widgets when the user selects save.  It doesn't need to be as each setting is changed.

How should I go about getting these values back out?  I tried retrieving the value by getting the widget from the Placeholder's controls collection, but it only seems to include elements place in the placeholder in the markup, not those added in the code-behind.

Thank you for any help you can provide.

2 Answers, 1 is accepted

Sort by
0
Accepted
Sebastian
Telerik team
answered on 05 Aug 2011, 09:52 AM
Hello Ryan,

Creating ASP.NET AJAX server controls like ours (or UI widgets, as you call them) dynamically after PageLoad is improper way to instantiate them. You can test that with a regular ASP.NET button created programmatically in the PreRender phase of the lifecycle - on subsequent postbacks the control will be lost and its viewstate/events will be corrupted.

Therefore, consider instantiating the UI controls at runtime on PageInit/PageLoad or the CreateChildControls method (in case you wrap them in other ASP.NET control). See this article for further reference.

Best regards,
Sebastian
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Ryan
Top achievements
Rank 1
answered on 05 Aug 2011, 02:36 PM
Thank you for your prompt reply.

I moved my code to PageInit instead and everything works now.  Thanks.
Tags
General Discussions
Asked by
Ryan
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Ryan
Top achievements
Rank 1
Share this question
or