Wednesday, March 21, 2012

Question: UpdatePanel and TwoWay binding

I have a FormView control and UpdatePanel inside EditItemTemplate. It seams like ControlBuilder doesn't generate ExtractValues for controls that are in UpdatePanel and in result their values doesn't get updated.

I wonder if this behavior is by design or it is bug?

Thanks!

do u try this in the page_load event?


See the example

<asp:FormViewID="FormView1"runat="server"DefaultMode="Edit" DatasourceID="ObjectDS"><EditItemTemplate>

....

<asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="conditional"><ContentTemplate><asp:DropDownListID="lstType"SelectedValue='<%# Bind("TypeID")%>'runat="server"DataSourceID="TypeDS"DataValueField="ID"DataTextField="Name"AutoPostBack="true"></asp:DropDownList><asp:TextBoxID="txtTypeDescription"runat="server"Text='<%#Bind("TypeDescription") %>'Enabled='<%#Eval("TypeID").ToString()=="Other"%>'/></ContentTemplate></asp:UpdatePanel>

...

</EditItemTemplate></asp:FormView>

When I call Form1.UpdateItem() values for "TypeID" and "TypeDescription" fields are not updated in the DataSource. I have found that in "__ExtractValues" method generated by ASP.NET the code for extracting values from "txtTypeDescription" and "lstType" is missing so their values are not passed to the DataSource. If I remove the UpdatePanel evrithig is OK and the code appears again. I have found that that EditItemTemplate property of the FormView control is marked with [TemplateContainerAttribute(typeof(FormView), BindingDirection.TwoWay)] and ContentTemplate of a UpdatePanel is not. So I wonder if this behavior is by design or it is a bug?

Workaround is to place the whole FormView in the UpdatePanel.


you have some issue as link below:

http://forums.asp.net/thread/1511598.aspx

you have to add build your dropdownlist first then add UpdatePanel later.

so you can do it in the page_Load and add UpdatePanel in code behind.

Hope this help

No comments:

Post a Comment