Hello everyone,
First of all, I'm using WebCombo v6.3 (and ASP.NET 2.0)
I have a webcombo aspx markup below:
<igcmbo:WebCombo ID="wc" runat="server"> </igcmbo:WebCombo>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
Then in the codebehind I enable xml HTTP, editable, type ahead suggest, subscribe and implement InitializeDataSource event handler.
using System;using System.Web;using Infragistics.WebUI.WebCombo;public partial class Default2 : System.Web.UI.Page{ protected override void OnInit(EventArgs e) { wc.InitializeDataSource += new Infragistics.WebUI.WebCombo.InitializeDataSourceEventHandler(wc_InitializeDataSource); base.OnInit(e); } void wc_InitializeDataSource(object sender, WebComboEventArgs e) { e.Combo.DataSource = TestClass.SelectAll().Tables[0].DefaultView; e.Combo.DataTextField = "Name"; e.Combo.DataValueField = "ID"; e.Combo.DataBind(); } protected void Page_Load(object sender, EventArgs e) { // *** To use DataSourceID comment out InitializeDataSource subscription // in OnInit override and uncomment the 3 lines below //wc.DataSourceID = "ObjectDataSource1"; //wc.DataTextField = "Name"; //wc.DataValueField = "ID"; wc.Editable = true; wc.EnableXmlHTTP = true; wc.ComboTypeAhead = TypeAhead.Suggest; } protected void Button1_Click(object sender, EventArgs e) { // value returns null on second second button click object a = wc.DataValue; }}
And here's the code for the SelectAll method used for the datasource (a simple DataSet)
public static DataSet SelectAll() { // TODO: implement SelectAll - this is for testing only DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataColumn col1 = new DataColumn("ID", typeof(int)); DataColumn col2 = new DataColumn("Name"); dt.Columns.Add(col1); dt.Columns.Add(col2); DataRow row1 = dt.NewRow(); row1[col1] = 1; row1[col2] = "Name 1"; dt.Rows.Add(row1); DataRow row2 = dt.NewRow(); row2[col1] = 2; row2[col2] = "Name 2"; dt.Rows.Add(row2); ds.Tables.Add(dt); return ds; }
Now when running the page, this is what happens:
1. page loads for the first time
2. select an item in the combo, then click button (thus 1st postback)
3. notice that wc.DataValue is retrieved correctly
4. after the page renders, click the button again (don't touch/change combo) (thus 2nd postback)
5. wc.DataValue returns null (at least in my case)
Furthermore, when I use DataSourceID instead of the InitializeDataSource approach, the problem doesn't occur. I'm not sure if I'm missing something.
Hope someone can verify this behavior if this is indeed an issue?
Hello,
In my example, I'm not talking about the 'SelectedRowsChange' server event handler.
An Ajax enabled WebCombo is binding automatically during the 'InitializeDataSource' event.
If the programmer is not careful, simply by doing a full PostBack by pressing the 'Save' button (without even changing the selected item of the webCombo) can lead to a wrong 'webCombo.DataValue' value on the server.
The details to care about in this situation are already mentioned at points a) and b) of my comment.
Attached is a screen capture.
Attached is a working project demonstrating how an Ajax enabled WebCombo can be fooled to return an incorrect webCombo.DataValue when a full PostBack occurs.
In my example I use Infragistics 7.3 Vol 3 (7.3.20073.1049)
a) The first detail to remember is do not call webCombo.DataBind() during the _InitializeDataSource() event handler. If you need to bind, do it once when the web page initially loads (i.e. IsPostBack == false) on Page_Load
b) When a pushbutton (say 'Save') is clicked, that causes a full postback of the web page. The second detail to remember is that the datasource must have exactly the same rows before and after the full PostBack!!
So do not forget: when the full PostBack is fired, the datasource must have exactly the same rows as it had before the full PostBack was fired,
otherwise you'll have a suprise, the webCombo.DataValue is incorrect on the server.
I have exactly the same problem using 7.3
Here is my code:
<igcmbo:WebCombo ID="PropertyCombo" runat="server" BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" ForeColor="Black" SelBackColor="DarkBlue" SelForeColor="White" Version="4.00" DataTextField="Property_Name" DataValueField="Property_Id" Editable="True" DisplayValue="" EnableXmlHTTP="true" ComboTypeAhead="Suggest" OnInitializeDataSource="PropertyCombo_InitializeDataSource" Font-Names="Verdana" Font-Size="10pt">
Protected Sub PropertyCombo_InitializeDataSource(ByVal sender As Object, ByVal e As Infragistics.WebUI.WebCombo.WebComboEventArgs) Me.PropertyCombo.DataSource = GetPropertyDataSet() End Sub
-----------------
I didn't call any databind method. Please help.