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

[Solved] Problem with ajaxifyinng a repeater inside a FormView

2 Answers 222 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Winnie
Top achievements
Rank 1
Winnie asked on 04 Aug 2009, 09:02 PM
Hi Telerik team,

I am adding some controls dynamically to a Repeater which is inside a FormView.

protected

 

void DynamicRepeater_ItemCreated(Object sender, RepeaterItemEventArgs e)

 

{

 

IDictionary

 

<string, string> values = RetrieveValues();

 

 

RadComboBox combo= new RadComboBox();

 

//DropDownList combo= new DropDownList();
combo.ID =

"SomeId";

 

combo.DataSource = values;

combo.DataValueField =

"Key";

 

combo.DataTextField =

"Value";

 

e.Item.Controls.Add(combo)

 

}

There is another RadComboBox control  named TypeComboBox with AutoPostBack="true" inside the FormView.
Whenever the TypeComboBox selection changes, the repeater needs to be rebound and the dynamic controls will be recreated inside the repeater.

So I added the following code to ajaxify the repeater:
protected void Page_PreRender(object sender, EventArgs e)

 

{

 

 

 

RadComboBox

 

typeComboBox = (RadComboBox)FormView1.FindControl("TypeComboBox ");

 

 

 

 

RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(typeComboBox , (Repeater)FormView1.FindControl("DynamicRepeater"));

 

 

}

This does not work.The point is when I replace the RadComboBox with an Asp DropDownList  ,the ajax works fine.So I assume the problem might be happening by the RadComboBox.
Note that Ajaxifying the whole FormView is not an option for me, because I don't want to lose the data that user entered in the other controls in the FormView after selecting the Type.

 
I had a previous issue with the ajaxifying other controls like Panel and PlaceHolder inside a FormView(Support ID:228263 -- Problem with RadAjaxManager and Panel or PlaceHolder inside a FormView), but I am afraid the answer was not very saticefying because like I explained the whole FormView shouldn't be refreshed in my case.

What can I do to solve this issue?

Thanks in advance for your help.
Sima

2 Answers, 1 is accepted

Sort by
0
Winnie
Top achievements
Rank 1
answered on 05 Aug 2009, 06:17 PM

I did more test on this problem and I found out that the RadComboBox has problem when created dynamically in the Repeater :

In Aspx page I have this repeater inside the FormView:

<
asp:Repeater ID="DynamicRepeater" DataSourceID="ObjectDataSource1" runat="server"

 

OnItemCreated="DynamicRepeater_ItemCreated">

 

 

 

 

</

 

asp:Repeater>

 

 

If I add the combobox like this:
protected

 

void DynamicRepeater_ItemCreated(Object sender, RepeaterItemEventArgs e)

 

{
Literal l1 = new Literal();

 

l1.Text =

"<tr><td>";

 

 

Literal l2 = new Literal();

 

l1.Text =

"</td></tr>";

 

 

 

 

//DropDownList c = new DropDownList();

 

 

RadComboBox

 

c = new RadComboBox();

 

 

 

c.ID =

"i" + e.Item.ItemIndex.ToString();

 

 

 

e.Item.Controls.Add(l1);

e.Item.Controls.Add(c);

e.Item.Controls.Add(l2);

}
 I will get 2 javascript errors when loading the page and combobox will not be created correctly.If I replace the RadComboBox with DropDownList , it works fine.The DropDownList is being created and Ajax will work correctly.By changing the TypeComboBox  selection, the repeater will be recreated(As I explained in previous post).

The only way I can create RadComboBox inside the repeater dynamically without the runtime error is this way:

protected void DynamicRepeater_ItemCreated(Object sender, RepeaterItemEventArgs e)

{

 

TableRow row = new TableRow();

 

 

 

TableCell cell1 = new TableCell();

 

 

//DropDownList c = new DropDownList();

 

 

RadComboBox

 

c = new RadComboBox();

 

 

c.ID =

"i" + e.Item.ItemIndex.ToString();

 

 

 

 

 

cell1.Controls.Add(c);

row.Controls.Add(cell1);

e.Item.Controls.Add(row);

 

}

or having a static placeholder inside the Tr Td tags and add the ComboBox to it:

 

<

 

asp:Repeater ID="DynamicRepeater" DataSourceID="ObjectDataSource1" runat="server"

 

 

OnItemCreated="DynamicRepeater_ItemCreated">

 

 

 

 

 

<ItemTemplate>

 

 

 

 

 

<tr>

 

 

 

 

 

<td>

 

 

 

 

 

<asp:PlaceHolder ID="p1" runat="server"></asp:PlaceHolder>

 

 

 

 

 

</td>

 

 

 

 

 

</tr>

 

 

 

 

 

</ItemTemplate>

 

 

 

 

 

</asp:Repeater>

 

 

 

(please see this post on this:
http://www.telerik.com/community/forums/reply-thread.aspx?messageId=0&threadId=229083)

This way the creation is fineI don't get error on loading,but Ajax is not working.When user changes the TypeComboBox  selection,will get the unKnown runtime error.
I have tested this with UpdatePanel(instead of RadAjaxManager) too and I got the same result.
I don't want to replace the RadComboBox with DropDownList because it makes my forms inconsistent.

Please let me know if you have any solution.

Thanks,
Sima

0
Veselin Vasilev
Telerik team
answered on 06 Aug 2009, 02:17 PM
Hello Winnie,

The javascript problems seems to be created by the <tr><td> that you are adding on the server. I have removed them and surrounded the repeater with <tr><td> and the errors are gone.

Please find attached the modified project.


Regards,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Ajax
Asked by
Winnie
Top achievements
Rank 1
Answers by
Winnie
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or