Using Infragistics 2010 v3, we have a very simple form with a WebDatePicker and a button. When entering a value in the WebDatePicker, and clicking the button for a postback, we do not see the date value entered on the code-behind.
We experience the same behavior with the WebDateTimeEditor control.
Has anyone else experienced this? I have attached a zip file with the form files.
Thanks.
Victor, thanks for the quick reply. I came up with a similar fix as your option 2, but yours is definitely cleaner.
Hi Calvin,
You have few options. Below are 2 of them.
1. Create a dummy WebDatePicker (applied to any control) and fake its postData loading. Below is example,protected void Page_Load(object sender, EventArgs e){ WebDatePicker dp = new WebDatePicker(); dp.ID = "WebDatePicker1"; //id of your editor this.Form.Controls.Add(dp2); dp.LoadPostData("", this.Request.Form); object date = dp.Value; // remove dp...}
2. Get date fields directly from clientState. Values modified on client, appear as last object/string within array. First 2 characters/digits contain states (disabled, focus, etc.) The rest of characters represent 7 date fields in format year-month-day-hours-minutes-seconds-milliseconds. Below is possible "parse" example:
protected void Page_Load(object sender, EventArgs e){ // assume that following was used to create editor: //WebDatePicker dp = new WebDatePicker(); //dp.ID = "WebDatePicker1"; //this.Form.Controls.Add(dp); string clientValue = this.Request.Form["WebDatePicker1_clientState"]; if (!string.IsNullOrEmpty(clientValue)) { string[] fields = clientValue.Split(','); string val = fields[fields.Length - 1].Replace("\"", "").Replace("]", "").Substring(2); fields = val.Split('-'); int year = int.Parse(fields[0]); int month = int.Parse(fields[1]); int day = int.Parse(fields[2]); int hour = int.Parse(fields[3]); int min = int.Parse(fields[4]); int sec = int.Parse(fields[5]); int ms = int.Parse(fields[6]); DateTime date = new DateTime(year, month, day, hour, min, sec, ms); }}
Victor,
I'm in the middle of upgrading our application to version 12.1 and having the exact issue that you just mentioned. I would like to retrieve the modifed date value from the form on the server side. Unfortunately, like you said, the value contains other information. How would you go about getting just the date value?
The following is the entire form value from the WebDatePicker1_clientState. I'm only interested in the MMDDYYYY format (1/20/2013) of the date.
|0|052013-1-20-0-0-0-0||[[null,[],null],[{},[]],"052013-1-20-0-0-0-0"]
Thanks,Calvin
Hi anbusel,
If you create controls dynamically, then you should consider architecture of .NET. The viewstate and events of dynamically created control may work only if that control has unique value of ID and that control is recreated by exactly same way in absolutely all sessions including not only initialization, but also all possible postbacks (button clicks, __doPostBack, etc.).In this situation server should handle viewState and events automatically.Exactly the same should happen not only with WebDatePicker, but with any other standard .NET control.
If you create control conditionally (for example on button click), then that control will exist only to the next postback (which should be obvious). If within that next postback that control was not recreated with same ID and at proper time (before loadViewState), then no server events attached to that control will be triggered and ViewState (client values) for that control will fail as well.
If you have that "conditional" scenario, then events and client values are actually available on server within Request.Form object, though, server is not able to interpret them and therefore they are lost. It means that if application needs those values, then it should extract them manually. The Form contains information about control which triggered postback and client values of fields as well. In case WebDatePicker, its client value (field with id similar to WebDatePicker1_clientState) besides modified value, contains other information (focus, enabled state, etc.), therefore, getting value without knowing rules of that field is problematic, though possible.
I suggest you to adjust logic of your applicaiton to recreate WebDatePicker in each session using exactly same ID. In this case no special codes/logic to get value will be required.
Hi,
I m using Infragistics version 12.1 and facing the same problem. I m dynamically creating the WebDatePicker Controls. The WebDatePicker.Text and WebDatePicker.Value always returns empty value in my code behind aspx.vb file.
I tried the above option too by adding <xhtmlConfirmance Mode = "Transitional"/>, but didnt worked for me.
Please let me know some suggestions. its urgent.
Thanks,