Implementing AutoPostBack on Infragistics WebCombo
I use Infragistics NetAdvantage control suite for UI development at work. If you hate UI development like me, these tools can help out tremendously. While working with their WebCombo control, a much more powerful version of the ASP.Net DropDownList control – I noticed the WebCombo was sorely missing is the AutoPostBack property.
I’ll be explaining how to implement an AutoPostBack property on a UserControl that contains a single Infragistics WebControl.
On your HTML page, add the following tag after the end of your opening WebCombo tag:
<CLIENTSIDEEVENTS AfterSelectChange="itgtbl_needPostBack('{0}')"></CLIENTSIDEEVENTS>
Create a basic AutoPostBack property on the codebehind of your UserControl.
protected bool autoPostBack;
public bool AutoPostBack
{
get{return this.autoPostBack;}
set{this.autoPostBack = value;}
}
Now you need to add a method that either sets up your WebCombo so that it automatically posts back, or does not generate any client code to post back. You can decide when you want to call this method in your code
private void SetupAutoPostback()
{
if(this.autoPostBack)
{
string gridClientID = string.Empty;
foreach(Control control in this.YOUR_COMBO_HERE.Controls)
{
Infragistics.WebUI.UltraWebGrid.UltraWebGrid grid = control as Infragistics.WebUI.UltraWebGrid.UltraWebGrid;
if(grid != null)
{
gridClientID = grid.ClientID;
break;
}
}
this.YOUR_COMBO_HERE.ClientSideEvents.AfterSelectChange = string.Format(this.YOUR_COMBO_HERE.ClientSideEvents.AfterSelectChange, gridClientID);
}
else
{
this.YOUR_COMBO_HERE.ClientSideEvents.AfterSelectChange = string.Empty;
}
}
Run your page – your combo should now post back automatically when the selected index changes.
Technorati Tags: Infragistics, AutoPostBack, WebCombo