I'm in the process of converting my Componentart grid to Telerik and I encountered this VERY bizarre behavior.
Clicking on any of the command buttons (add a record, edit, refresh) causes the following error:
Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.
Here's the weird part...it doesn't do it every time. I can sit on the same page and click the add a record button 20 times and get that error, but on the 21st click, it will work. Same with the edit button...click it 10 times or so and get that error, but the next click and it goes into edit mode.
I've been scratching my head for the last hour and I can't seem to figure it out.
Here's my code...very basic since I'm still converting
here's the code-behind
Any ideas on what could be causing this strange behavior?
Clicking on any of the command buttons (add a record, edit, refresh) causes the following error:
Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.
Here's the weird part...it doesn't do it every time. I can sit on the same page and click the add a record button 20 times and get that error, but on the 21st click, it will work. Same with the edit button...click it 10 times or so and get that error, but the next click and it goes into edit mode.
I've been scratching my head for the last hour and I can't seem to figure it out.
Here's my code...very basic since I'm still converting
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> |
<AjaxSettings> |
<telerik:AjaxSetting AjaxControlID="RadGrid1"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="RadGrid1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
</AjaxSettings> |
</telerik:RadAjaxManager> |
<telerik:RadGrid ID="RadGrid1" Skin="Default2006" |
Width="160" |
AllowSorting="True" |
PageSize="10" |
ShowFooter="True" |
AllowPaging="True" |
OnNeedDataSource="RadGrid1_NeedDataSource" |
OnInsertCommand="RadGrid1_InsertCommand" |
OnDeleteCommand="RadGrid1_DeleteCommand" |
OnUpdateCommand="RadGrid1_UpdateCommand" |
Gridlines="Both" |
runat="server"> |
<MasterTableView CommandItemDisplay="Top" EditMode="InPlace" DataKeyNames="den_id" Width="100%" HorizontalAlign="NotSet" AutoGenerateColumns="False"> |
<Columns> |
<telerik:GridBoundColumn UniqueName="den_id" DataField="den_id" Visible="false" /> |
<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"> |
<ItemStyle Width="85" /> |
</telerik:GridEditCommandColumn> |
<telerik:GridBoundColumn DataField="den_no" HeaderText="Den" UniqueName="den_no"> |
<ItemStyle Width="50" /> |
</telerik:GridBoundColumn> |
<telerik:GridDropDownColumn UniqueName="den_type_id" DataSourceID="DenTypeDataSource" ListValueField ="den_type_id" ListTextField="den_type_nm" HeaderText="Den Type" DataField="den_type_id"> |
<ItemStyle Width="100" /> |
</telerik:GridDropDownColumn> |
<telerik:GridBoundColumn DataField="den_nm" HeaderText="Den Name" UniqueName="den_nm"> |
<ItemStyle Width="150" /> |
</telerik:GridBoundColumn> |
<telerik:GridDropDownColumn UniqueName="den_ldr_id" DataSourceID="DenLeaderDataSource" ListValueField ="adult_id" ListTextField="adult_nm" HeaderText="Den Leader" DataField="den_ldr_id"> |
<ItemStyle Width="100" /> |
</telerik:GridDropDownColumn> |
<telerik:GridButtonColumn UniqueName="DeleteColumn" ConfirmText="Delete Den?" ButtonType="ImageButton" CommandName="Delete" > |
<ItemStyle Width="30" /> |
</telerik:GridButtonColumn> |
</Columns> |
</MasterTableView> |
<PagerStyle Mode="NextPrevAndNumeric" /> |
</telerik:RadGrid> |
<asp:SqlDataSource ID="DenTypeDataSource" runat="server" /> |
<asp:SqlDataSource ID="DenLeaderDataSource" runat="server" /> |
here's the code-behind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
PageTitle.InnerText = "Scout Central-Manage Dens" |
DenTypeDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("LocalSqlServer").ToString |
DenTypeDataSource.SelectCommand = "SELECT [sc_den_type].[den_type_id], [sc_den_type].[den_type_nm] FROM [sc_den_type] WHERE [sc_den_type].[unit_type_id] = " & Profile.UnitTypeID + " ORDER BY [sc_den_type].[den_type_id] ASC" |
DenLeaderDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("LocalSqlServer").ToString |
DenLeaderDataSource.SelectCommand = "SELECT [sc_adult].[adult_id], [sc_adult].[adult_fnm] + ' ' + [sc_adult].[adult_lnm] AS [adult_nm] FROM [sc_adult] WHERE [sc_adult].[unit_id] = " & Profile.UnitID |
End Sub |
Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource |
RadGrid1.DataSource = GetDataTable("SELECT [sc_den].[den_id], [sc_den].[den_no], [sc_den].[den_type_id], [sc_den].[den_nm], [sc_den].[den_ldr_id] FROM [sc_den] WHERE [sc_den].[unit_id]=" & Profile.UnitID & " ORDER BY [sc_den].[den_no] ASC") |
End Sub |
Public Function GetDataTable(ByVal query As String) As DataTable |
Dim connstr = ConfigurationManager.ConnectionStrings("LocalSqlServer").ToString |
Dim dbconn As New SqlConnection(connstr) |
Dim dbadapter As New SqlDataAdapter(query, dbconn) |
Dim oTable1 As New DataTable("Dens") |
Try |
dbadapter.Fill(oTable1) |
Finally |
dbconn.Close() |
End Try |
Return oTable1 |
End Function |
Protected Sub RadGrid1_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) |
'Get the GridEditFormInsertItem of the RadGrid |
Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem) |
Dim sql As String = "" |
Dim den_no As String = (TryCast(item("den_no").Controls(0), TextBox)).Text |
Dim den_type_id As String = (TryCast(item("den_type_id").Controls(0), RadComboBox)).SelectedItem.Value |
Dim den_nm As String = (TryCast(item("den_nm").Controls(0), TextBox)).Text |
Dim den_ldr_id As String = (TryCast(item("den_ldr_id").Controls(0), RadComboBox)).SelectedItem.Value |
sql = "INSERT INTO [sc_den] ([unit_id], [den_type_id], [den_no], [den_nm], [den_ldr_id]) VALUES (" |
sql += Profile.UnitID + ", " |
sql += "'" + den_type_id + "', " |
sql += "'" + den_no + "', " |
sql += "'" + den_nm + "', " |
sql += "'" + den_ldr_id + "') " |
Try |
Dim connstr = ConfigurationManager.ConnectionStrings("LocalSqlServer").ToString |
Dim dbconn As New SqlConnection(connstr) |
dbconn.Open() |
Dim cmd As New SqlCommand(sql, dbconn) |
cmd.ExecuteNonQuery() |
dbconn.Close() |
Catch ex As Exception |
RadGrid1.Controls.Add(New LiteralControl("Unable to add Den. Reason: " + ex.Message)) |
e.Canceled = True |
End Try |
End Sub |
Protected Sub RadGrid1_DeleteCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) |
'Get the GridDataItem of the RadGrid |
Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) |
'Get the primary key value using the DataKeyValue. |
Dim sql As String = "" |
Dim den_id As String = item.OwnerTableView.DataKeyValues(item.ItemIndex)("den_id").ToString() |
sql = "DELETE FROM [sc_den] WHERE [den_id]=" + den_id + " " |
Try |
Dim connstr = ConfigurationManager.ConnectionStrings("LocalSqlServer").ToString |
Dim dbconn As New SqlConnection(connstr) |
dbconn.Open() |
Dim cmd As New SqlCommand(sql, dbconn) |
cmd.ExecuteNonQuery() |
dbconn.Close() |
Catch ex As Exception |
RadGrid1.Controls.Add(New LiteralControl("Unable to delete Den. Reason: " + ex.Message)) |
e.Canceled = True |
End Try |
End Sub |
Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) |
'Get the GridEditableItem of the RadGrid |
Dim item As GridEditableItem = TryCast(e.Item, GridEditableItem) |
'Get the primary key value using the DataKeyValue. |
Dim sql As String = "" |
Dim den_id As String = item.OwnerTableView.DataKeyValues(item.ItemIndex)("den_id").ToString() |
Dim den_no As String = (TryCast(item("den_no").Controls(0), TextBox)).Text |
Dim den_type_id As String = (TryCast(item("den_type_id").Controls(0), RadComboBox)).SelectedItem.Value |
Dim den_nm As String = (TryCast(item("den_nm").Controls(0), TextBox)).Text |
Dim den_ldr_id As String = (TryCast(item("den_ldr_id").Controls(0), RadComboBox)).SelectedItem.Value |
sql = "UPDATE [sc_den] SET " |
sql += "[den_no]='" + den_no + "', " |
sql += "[den_type_id]='" + den_type_id + "', " |
sql += "[den_nm]='" + den_nm + "', " |
sql += "[den_ldr_id]='" + den_ldr_id + "' " |
sql += "WHERE [den_id]=" + den_id + " " |
Try |
Dim connstr = ConfigurationManager.ConnectionStrings("LocalSqlServer").ToString |
Dim dbconn As New SqlConnection(connstr) |
dbconn.Open() |
Dim cmd As New SqlCommand(sql, dbconn) |
cmd.ExecuteNonQuery() |
dbconn.Close() |
Catch ex As Exception |
RadGrid1.Controls.Add(New LiteralControl("Unable to update Den. Reason: " + ex.Message)) |
e.Canceled = True |
End Try |
End Sub |
Any ideas on what could be causing this strange behavior?