Tuesday, June 19, 2012

Remove Commas from WebNumericEdit


When using Infragistics WebNumericEdit, unnecessary commas have to be removed to use this control as a general numeric control. This format is inherited from NumberFormatInfo class, in order to modify this behavior new instance on this class has to be created and set the NumberGroupSeparator property. WebNumericEdit control has the propery called Culture, so a new CultureInfo object can be assign with the required  NumberGroupSeparator. Following code snippet can be use to achieve required behavior.

//C#
using System.Globalization;

// In the page load event
CultureInfo culInfo=new CultureInfo("en-US");  //instance of CultureInfo class

NumberFormatInfo numFromatInfo = new NumberFormatInfo();  // instance of NumberFormatInfo class
numFromatInfo.NumberGroupSeparator= string.Empty;  //set NumberGroupSeparator any string you want

culInfo.NumberFormat=numFromatInfo;

this.WebNumericEdit1.Culture = culInfo; //WebNumericEdit1 is the control to be applied with the new number format

 
This code has to be in the page load event and has to be called in the post backs also .

Wednesday, June 13, 2012

Creating a Multi-Text DropDownList from general ASP.NET DropDownList

In some projects there may be a requirement to bind multiple data fields with some pattern as the datatextfield such as "Name - Address". To achieve this requirement new column can be added to the datatable before bind data to the dropdownlist. Following C# code can be use to achieve this requirement.

DataColumn newColumn = new DataColumn("AddedColumn"); // Create a new data column
newColumn.Expression = "Name + ' - ' + Address"; //Name and Address are columns in datatable
dtData.Columns.Add(newColumn); //dtData is the datatable

ddDropDownList.DataTextField = "AddedColumn";

ddDropDownList.DataSource = dtData;
ddDropDownList.DataBind();

Like this any formatted string can be created using data table columns and bind to the DropDownList as the DataTextField. 


showModalDialog not returning value after a postback in Chrome

There is a bug in the Chrome browser engine, which is showModalDialog fails to return window.returnValue after childpage do any postback. This issue has been there for long time and status of the this issue is still available. More information on this issue can be found here.

For a solution for this issue update panels can be used to avoid unnecessary postbacks but this solution is not extendable for all the scenarios. The best solution posted in the stackoverflow can be found here.  What has done in this solution is, it uses the window.operner return value to get the return value in the Chrome. After postbacks also window.opener property in the modal dialog points to the caller window, so the result can be directly set to the returnValue property of the caller window(parent window).