Hello,
I am creating and configuring a WebDataGrid dynamically on my page. It works fine, however when I add any behaviours to the grid to allow the user to sort/filter etc, as soon as you try to use any of these features I get the error message "Microsoft JScript runtime error: ASP.NET Ajax client-side framework failed to load.".
My code to create the grid is as follows:
Private Sub BuildDataGrid() Dim DataGrid As New Infragistics.Web.UI.GridControls.WebDataGrid If p_DashboardObject.SummaryData.SummaryDataTable Is Nothing Then p_DashboardObject.ReBuildSummaryData() End If Dim DataTable As System.Data.DataTable = p_DashboardObject.SummaryData.SummaryDataTable If DataTable Is Nothing Then Dim Literal As New Literal Literal.Text = "No data available" Me.Controls.Add(Literal) End If DataGrid.Height = Unit.Percentage(100) DataGrid.Width = Unit.Percentage(100) DataGrid.AutoGenerateColumns = False DataGrid.DataSource = DataTable Dim DataColumn As System.Data.DataColumn Dim FormatString As String For Each DataColumn In DataTable.Columns If Not DataColumn.ColumnName Like "*" & Chr(1) & "*" Then Dim BoundField As New Infragistics.Web.UI.GridControls.BoundDataField(True) BoundField.DataFieldName = DataColumn.ColumnName BoundField.Key = DataColumn.ColumnName BoundField.Header.Text = p_DashboardObject.ColumnHeading(DataColumn.ColumnName) FormatString = p_DashboardObject.ColumnFormat(DataColumn.ColumnName) If FormatString <> "" Then If p_DashboardObject.NumericColumn(DataColumn.ColumnName) Then BoundField.DataFormatString = p_DashboardObject.PrimaryYAxis.numericPrefix & "{0:N" & p_DashboardObject.PrimaryYAxis.numberDecimals.ToString & "}" Else BoundField.DataFormatString = FormatString End If End If DataGrid.Columns.Add(BoundField) If p_DashboardObject.NumericColumn(DataColumn.ColumnName) Then DataGrid.Columns.Item(DataColumn.ColumnName).CssClass = "customRightDataAlign" DataGrid.Columns.Item(DataColumn.ColumnName).Header.CssClass = "customGridHeaderRight" Else DataGrid.Columns.Item(DataColumn.ColumnName).CssClass = "customLeftDataAlign" DataGrid.Columns.Item(DataColumn.ColumnName).Header.CssClass = "customGridHeaderLeft" End If End If Next If DataGrid.Behaviors.ColumnMoving Is Nothing Then DataGrid.Behaviors.Add(DataGrid.Behaviors.CreateBehavior(Of ColumnMoving)) End If DataGrid.Behaviors.ColumnMoving.Enabled = True If DataGrid.Behaviors.ColumnResizing Is Nothing Then DataGrid.Behaviors.Add(DataGrid.Behaviors.CreateBehavior(Of ColumnResizing)) End If DataGrid.Behaviors.ColumnResizing.Enabled = True If DataGrid.Behaviors.Filtering Is Nothing Then DataGrid.Behaviors.Add(DataGrid.Behaviors.CreateBehavior(Of Filtering)) End If DataGrid.Behaviors.Filtering.Enabled = True If DataGrid.Behaviors.Sorting Is Nothing Then DataGrid.Behaviors.Add(DataGrid.Behaviors.CreateBehavior(Of Sorting)) End If DataGrid.Behaviors.Sorting.Enabled = True DataGrid.ClientEvents.Initialize = "dg_Initialize" DataGrid.DataBind() Me.Controls.Add(DataGrid) End Sub
Thanks for the helpNick
First, the disclaimer that I'm not good at building controls in codebehind as you are doing.
However, the first thing that stands out to me is that WebDataGrid requires a ScriptManager or WebScriptManager to be on the page above the WebDataGrid, and I don't see where you are building one.
Thanks for your post Rob. However, there is a script manager on the page. This code is adding one of a number of controls on the page, tabs, treeview, splitter's etc, all of which are working fine.
RegardsNick
Hello Nick,
Thank you for your patience. I have been able to reproduce this issue. I have contacted development to gather more information about the cause and to work out a possible solution. I will update you with my progress in a few business days.
Please let me know if I may be of further assistance with this matter.
Sincerely,Mike P.Developer Support EngineerInfragistics, Inc.www.infragistics.com
Thanks Mike.
I recommend that you create the WebDataGrid inside the Page_Init. This is because the grid needs to be created before page load, because it needs to register all the scripts it’s going to use for behaviors, and this needs to occur before page load. I have created and attached a sample to demonstrate this.
Hi Mike,
Works for a simple case, however my DataGrid is created as part of a more complex object.
My page code is....
Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init BuildDataGrid() End Sub Private Sub BuildDataGrid() Dim ParentControl As New ParentControl Me.Form.Controls.Add(ParentControl) End SubEnd Class
The definition of ParentControl is ...
Imports Microsoft.VisualBasicImports Infragistics.Web.UI.GridControlsImports System.DataPublic Class ParentControl Inherits WebControl Protected Overrides Sub CreateChildControls() BuildDataGrid() End Sub Private Sub BuildDataGrid() Dim DataGrid As New Infragistics.Web.UI.GridControls.WebDataGrid DataGrid.ID = "DataGrid" DataGrid.DataSource = GetDepartments() DataGrid.CssClass = "Default" DataGrid.Height = Unit.Percentage(100) DataGrid.Width = Unit.Percentage(100) DataGrid.AutoGenerateColumns = False DataGrid.EnableAjax = True Dim boundField1 As New BoundDataField(True) boundField1.Key = "DepartmentID" boundField1.Header.Text = "Name" 'Bind to CompanyName field in data source boundField1.DataFieldName = "DepartmentID" Dim boundField2 As New BoundDataField(True) boundField2.Key = "DepartmentName" boundField2.Header.Text = "Name" 'Bind to CompanyName field in data source boundField2.DataFieldName = "DepartmentName" ' At this point you can set up a template for the template column ' ADD COLUMNS DataGrid.Columns.Add(boundField1) DataGrid.Columns.Add(boundField2) If DataGrid.Behaviors.ColumnMoving Is Nothing Then DataGrid.Behaviors.Add(DataGrid.Behaviors.CreateBehavior(Of ColumnMoving)) End If DataGrid.Behaviors.ColumnMoving.Enabled = True If DataGrid.Behaviors.ColumnResizing Is Nothing Then DataGrid.Behaviors.Add(DataGrid.Behaviors.CreateBehavior(Of ColumnResizing)) End If DataGrid.Behaviors.ColumnResizing.Enabled = True If DataGrid.Behaviors.Filtering Is Nothing Then DataGrid.Behaviors.Add(DataGrid.Behaviors.CreateBehavior(Of Filtering)) End If DataGrid.Behaviors.Filtering.Enabled = True If DataGrid.Behaviors.Sorting Is Nothing Then DataGrid.Behaviors.Add(DataGrid.Behaviors.CreateBehavior(Of Sorting)) End If DataGrid.Behaviors.Sorting.Enabled = True DataGrid.DataBind() Me.Controls.Add(DataGrid) End Sub Private Function GetDepartments() As DataTable Dim dt As DataTable = New DataTable("Departments") dt.Columns.Add("DepartmentID", GetType(Integer)) dt.Columns.Add("DepartmentName", GetType(String)) For i As Integer = 0 To 8 Step 1 dt.Rows.Add(New Object() {i, String.Format("Department {0}", i)}) Next dt.PrimaryKey = New DataColumn() {dt.Columns("DepartmentID")} Return dt End FunctionEnd Class
The problem still occurs in this case.
ThanksNick
Should have thought about the solution in more detail before posting. Changing ...
Protected Overrides Sub CreateChildControls() BuildDataGrid()End Subto ...Private Sub ParentControl_Init(sender As Object, e As System.EventArgs) Handles Me.Init BuildDataGrid()End Sub
solved it. Thanks for the help Mike.
Nick