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

checkbox control inside raddock dynamically created

2 Answers 127 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Ulises
Top achievements
Rank 1
Ulises asked on 08 Jan 2009, 10:52 PM
Hi guys


I have another problem using the raddock control when i put a checkbox (dynamically created too) inside of a contentcontainer.

1.- i create a raddock dynamically ( 3 for example)
2.- i create inside of this raddock (contentcontainer) a checkbox control (one for each raddock)
3.- Add a event handler for the checkbox ( like the example of  RadDock CreateRadDock()  dynamically) , in the function raddock CreateRadDock

CheckBox

 

chkIdeal = new CheckBox();

 

chkIdeal.CheckedChanged +=

new EventHandler(chkIdeal_CheckedChanged);

 

chkIdeal.AutoPostBack =

true;

 

 

if (iIdeal == 2)

 

chkIdeal.Enabled =

false;

 

 

else

 

chkIdeal.Enabled =

true;

 

dock.ContentContainer.Controls.Add(chkIdeal);


With this i add the checkbox control  to RadDock, but when i click the checkbox this dont do anything,and, of course, dont go fire the chkIdeal_CheckedChanged. I dont know if i need to add the control to the updatepanel control and add to the Asyncpostbacktrigger function this control. What can i do for use a control in this conditions?

thanks for everything.

2 Answers, 1 is accepted

Sort by
0
Joseph
Top achievements
Rank 1
answered on 10 Jan 2009, 12:23 AM
Ulises, I think you have two problems with your code here:

1.  You need to set an ID on your checkbox (e.g. chkIdeal.ID = "myCheckbox").  This ID needs to be the same every postback (which it should be unless you are messing with the ID's or the control hierarchy of any parent controls).  Don't worry about making its clientID unique, as .NET will take care of that for you (e.g. the full ID will ne changed to something like raddockA3434a343434343434_ctl0_myCheckbox automatically by the runtime, so you just need to set the main ID property).  In your case it's very important to set the ID because the order in which your controls are loaded will be different on the next postback since you added a new control to the page (and that may change the order in which the controls are added).
2.  You need to recreate that checkbox on every postback in the OnInit method of your user control (I'm assuming you're using the MyPortal.aspx example and therefore are loading up user controls).  I think you must already be doing this though or your checkboxes would actually dissapear on postback (-:  However are you doing it in the correct timing (e.g. in OnLoad or Page_Load)?  You also need to make sure to create it in the same order that it was created before within your user control, or you may run into behavior such as the checkbox losing its checked state (or taking its state from a control above or below it), and you may actually generate ViewState errors from the page itself (e.g. something along the lines of "Failed to load ViewState"--see this page for more info and solution if you run into that: http://www.telerik.com/community/forums/aspnet-ajax/docking/failed-to-load-view-state-error-when-moving-dynamically-created-widgets-around-the-raddocklayout.aspx).

I think the CreateRadDock code only uses the updatepanel for adding controls and not for responding to postsbacks of the docks' content controls themselves (e.g. any command that fires within your user control will still generate a full postback to the server unless you embed an updatepanel within your dock's user control).

I do know that the key to getting IPostBackEventHandler to attach events (such as CheckedChanged) to your custom controls is getting the ID's set the same and making sure your custom controls are created in the OnInit or Page_Load method so that the base.LoadViewState() and IPostBackEventHandler.RaisePostBackEvent methods of the container Page will correctly fire for your controls.

Give that a whirl and see if it helps.    

joseph
0
Nikolay Raykov
Telerik team
answered on 12 Jan 2009, 11:39 AM
Hi Ulises,

All you need to do is to create the check box control, set its AutoPostBack property to true, add an event handler for the CheckedChanged event and add it to the ContentContainer of the dock. These steps need to be repeated in Page_Init when you re-create the docks after a postback to the server.

I am not exactly sure why your check boxes do not cause a postback. Do you re-create them in Page_Init and re-attach the event handler for the CheckedChanged event? I suspect you do not re-create the check boxes as you should do - you need to repeat the steps I described.

For your convenience I created a sample test page in which I dynamically add RadDock controls with check boxes as their content. When you click on any of the check boxes a postback occurs.

Best wishes,
Nikolay Raykov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Dock
Asked by
Ulises
Top achievements
Rank 1
Answers by
Joseph
Top achievements
Rank 1
Nikolay Raykov
Telerik team
Share this question
or