Hi
In Sharepoint 2010 I created a web part with a dropdown that contain a list of the month and based on the selection some data is shown in a grid. If I don't ajaxify it, it works well. When I work with ajax , if I select first time imediately after the page is shown a month with no data, it show the grid empty, when I select back to a month that has data I get this error
"
Microsoft JScript runtime error: Sys.ArgumentUndefinedException: Value cannot be undefined.
Parameter name: type
".
If imediately after the page is shown I select a month with data and then a month without data and then a month with data i have no erorrs.
How I can fix the error ?
Thank you !
Hans
The code is here:
and here it is the c#
In Sharepoint 2010 I created a web part with a dropdown that contain a list of the month and based on the selection some data is shown in a grid. If I don't ajaxify it, it works well. When I work with ajax , if I select first time imediately after the page is shown a month with no data, it show the grid empty, when I select back to a month that has data I get this error
"
Microsoft JScript runtime error: Sys.ArgumentUndefinedException: Value cannot be undefined.
Parameter name: type
".
If imediately after the page is shown I select a month with data and then a month without data and then a month with data i have no erorrs.
How I can fix the error ?
Thank you !
Hans
The code is here:
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebPart_EstimatedFinalCostsUserControl.ascx.cs" Inherits="Project_EstimatedFinalCosts.WebPart_EstimatedFinalCosts.WebPart_EstimatedFinalCostsUserControl" %>
<%@ Register Assembly="Telerik.Web.UI, Version=2013.1.417.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"
Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
DefaultLoadingPanelID
=
"RadAjaxLoadingPanel1"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGrid1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
></
telerik:AjaxUpdatedControl
>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadDropDownYears"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
></
telerik:AjaxUpdatedControl
>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadDropDownMonths"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
></
telerik:AjaxUpdatedControl
>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadDropDownJobMaster"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
></
telerik:AjaxUpdatedControl
>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxLoadingPanel
runat
=
"server"
ID
=
"RadAjaxLoadingPanel1"
Skin
=
"WebBlue"
/>
<
asp:Panel
ID
=
"Panel1"
runat
=
"server"
>
<
table
style
=
"width: 500px;"
>
<
tr
>
<
td
>
Current
</
td
>
<
td
>
<
telerik:RadDropDownList
ID
=
"RadDropDownYears"
runat
=
"server"
Skin
=
"WebBlue"
AutoPostBack
=
"True"
onselectedindexchanged
=
"RadDropDownYears_SelectedIndexChanged"
>
</
telerik:RadDropDownList
>
</
td
>
<
td
>
<
telerik:RadDropDownList
ID
=
"RadDropDownMonths"
runat
=
"server"
Skin
=
"WebBlue"
AutoPostBack
=
"True"
onselectedindexchanged
=
"RadDropDownMonths_SelectedIndexChanged"
>
</
telerik:RadDropDownList
>
</
td
>
<
td
>
<
telerik:RadDropDownList
ID
=
"RadDropDownJobMaster"
runat
=
"server"
Skin
=
"WebBlue"
AutoPostBack
=
"True"
onselectedindexchanged
=
"RadDropDownJobMaster_SelectedIndexChanged"
DropDownWidth
=
"500px"
DropDownHeight
=
"200px"
EnableVirtualScrolling
=
"true"
>
<
ItemTemplate
>
<
table
>
<
tr
>
<
td
style
=
"width: 10%"
>
<%# DataBinder.Eval(Container.DataItem, "JobNo")%>
</
td
>
<
td
style
=
"width: 80%"
>
<%# DataBinder.Eval(Container.DataItem, "JobName")%>
</
td
>
<
td
style
=
"width: 10%"
>
<%# DataBinder.Eval(Container.DataItem, "JobStatus")%>
</
td
>
</
tr
>
</
table
>
</
ItemTemplate
>
</
telerik:RadDropDownList
>
</
td
>
</
tr
>
</
table
>
</
asp:Panel
>
<
br
/>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"False"
CellSpacing
=
"0"
GridLines
=
"None"
AllowFilteringByColumn
=
"True"
AllowPaging
=
"True"
AllowSorting
=
"True"
AutoGenerateEditColumn
=
"True"
OnUpdateCommand
=
"RadGrid1_UpdateCommand"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
Skin
=
"WebBlue"
ShowStatusBar
=
"true"
>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"True"
/>
</
ClientSettings
>
<
MasterTableView
EditMode
=
"EditForms"
DataKeyNames
=
"EFCId"
CommandItemDisplay
=
"Top"
InsertItemPageIndexAction
=
"ShowItemOnCurrentPage"
GridLines
=
"None"
TableLayout
=
"Auto"
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
></
CommandItemSettings
>
<
Columns
>
<
telerik:GridTemplateColumn
HeaderText
=
"Year"
ItemStyle-Width
=
"100px"
>
<
ItemTemplate
>
<%#DataBinder.Eval(Container.DataItem, "Year")%>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadComboBox
runat
=
"server"
ID
=
"RadComboBox1"
EnableLoadOnDemand
=
"True"
OnItemsRequested
=
"RadComboBox1_ItemsRequested"
DataTextField
=
"YearNo"
DataValueField
=
"YearNo"
Text='<%#DataBinder.Eval(Container.DataItem,"Year")%>' Skin="WebBlue"
MarkFirstMatch="True" >
</
telerik:RadComboBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"Contains"
DataField
=
"JobNo"
ForceExtractValue
=
"Always"
HeaderText
=
"Job No"
SortExpression
=
"JobNo"
ItemStyle-Width
=
"120px"
>
<
HeaderStyle
Width
=
"120px"
/>
<
ItemStyle
Width
=
"120px"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"Contains"
DataField
=
"JobName"
HeaderText
=
"Job Name"
SortExpression
=
"JobName"
ItemStyle-Width
=
"500px"
>
<
HeaderStyle
Width
=
"500px"
/>
<
ItemStyle
Width
=
"500px"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
AllowFiltering
=
"false"
DataField
=
"EFCAmount"
HeaderText
=
"EFC Amount"
SortExpression
=
"EFCAmount"
ItemStyle-Width
=
"100px"
>
<
HeaderStyle
Width
=
"100px"
/>
<
ItemStyle
Width
=
"100px"
/>
</
telerik:GridBoundColumn
>
</
Columns
>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
Visible
=
"True"
FilterControlAltText
=
"Filter ExpandColumn column"
Created
=
"True"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
></
EditColumn
>
</
EditFormSettings
>
<
PagerStyle
PageSizeControlType
=
"RadComboBox"
></
PagerStyle
>
</
MasterTableView
>
<
PagerStyle
PageSizeControlType
=
"RadComboBox"
></
PagerStyle
>
<
FilterMenu
EnableTheming
=
"True"
>
<
CollapseAnimation
Duration
=
"200"
Type
=
"OutQuint"
></
CollapseAnimation
>
</
FilterMenu
>
</
telerik:RadGrid
>
and here it is the c#
using
System;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Collections.Generic;
using
System.Linq;
using
Project_SqlDataLibrary;
using
Microsoft.SharePoint.Administration;
using
Telerik.Web.UI;
using
System.Collections;
namespace
Project_EstimatedFinalCosts.WebPart_EstimatedFinalCosts
{
public
partial
class
WebPart_EstimatedFinalCostsUserControl : UserControl
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
LoadAndConfigureYearData();
LoadAndConfigureMonthData();
LoadAndConfigureActiveJobData();
}
}
private
void
LoadAndConfigureActiveJobData()
{
try
{
int
year = RadDropDownYears.SelectedValue ==
null
? DateTime.Now.Year : Convert.ToInt32(RadDropDownYears.SelectedValue);
int
month = RadDropDownMonths.SelectedValue ==
null
? DateTime.Now.Month : Convert.ToInt32(RadDropDownMonths.SelectedValue);
IEnumerable<EFC_JobMaster> list = SQL_EFC.GetAll_ActiveJobList(year,month,
true
);
RadDropDownJobMaster.DataSource = list;
RadDropDownJobMaster.DataTextField =
"JobName"
;
RadDropDownJobMaster.DataValueField =
"JobNo"
;
RadDropDownYears.SelectedValue =
"0"
;
RadDropDownJobMaster.DataBind();
}
catch
(Exception ex)
{
SPDiagnosticsService.Local.WriteTrace(0,
new
SPDiagnosticsCategory(
"Autoreportlinks error: "
, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace);
}
}
private
void
LoadAndConfigureYearData()
{
try
{
IEnumerable<Year> list = SQL_Misc.GetAll_YearsList();
int
index = list.FirstOrDefault(x => x.CurrentWorkYear ==
true
).YearNo;
RadDropDownYears.DataSource = list;
RadDropDownYears.DataTextField =
"YearNo"
;
RadDropDownYears.DataValueField =
"YearNo"
;
RadDropDownYears.SelectedValue = index.ToString().Trim();
RadDropDownYears.DataBind();
}
catch
(Exception ex)
{
SPDiagnosticsService.Local.WriteTrace(0,
new
SPDiagnosticsCategory(
"Autoreportlinks error: "
, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace);
}
}
private
void
LoadAndConfigureMonthData()
{
try
{
IEnumerable<Month> list = SQL_Misc.GetAll_MonthsList();
RadDropDownMonths.DataSource = list;
RadDropDownMonths.DataTextField =
"MonthName"
;
RadDropDownMonths.DataValueField =
"MonthNo"
;
int
curMonth = DateTime.Now.Month;
if
(curMonth == 1)
curMonth = 12;
else
curMonth--;
RadDropDownMonths.SelectedValue = curMonth.ToString().Trim();
RadDropDownMonths.DataBind();
}
catch
(Exception ex)
{
SPDiagnosticsService.Local.WriteTrace(0,
new
SPDiagnosticsCategory(
"Autoreportlinks error: "
, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace);
}
}
#region "Events"
protected
void
RadGrid1_UpdateCommand(
object
source, GridCommandEventArgs e)
{
var editableItem = ((GridEditableItem)e.Item);
var efcId = (
int
)editableItem.GetDataKeyValue(
"EFCId"
);
//you have the primary key value to required for update
//get the value of the combobox
GridEditFormItem formItem = e.Item
as
GridEditFormItem;
var x = formItem.FindControl(
"RadComboBox1"
);
RadComboBox dd = x
as
RadComboBox;
int
comboVal = Convert.ToInt32(dd.SelectedValue);
////this gets the other values from text input in values variable
Hashtable values =
new
Hashtable();
editableItem.ExtractValues(values);
}
protected
void
RadGrid1_NeedDataSource(
object
source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
try
{
int
year = RadDropDownYears.SelectedValue ==
null
? DateTime.Now.Year : Convert.ToInt32(RadDropDownYears.SelectedValue);
int
month = RadDropDownMonths.SelectedValue ==
null
? DateTime.Now.Month : Convert.ToInt32(RadDropDownMonths.SelectedValue);
string
jobno = String.Empty;
RadGrid1.DataSource = SQL_EFC.GetAll_List(year, month, jobno);
}
catch
(Exception ex)
{
SPDiagnosticsService.Local.WriteTrace(0,
new
SPDiagnosticsCategory(
"Autoreportlinks error: "
, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace);
}
}
protected
void
RadDropDownJobMaster_SelectedIndexChanged(
object
sender, DropDownListEventArgs e)
{
try
{
RadGrid1.Rebind();
}
catch
(Exception ex)
{
SPDiagnosticsService.Local.WriteTrace(0,
new
SPDiagnosticsCategory(
"Autoreportlinks error: "
, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace);
}
}
protected
void
RadDropDownYears_SelectedIndexChanged(
object
sender, DropDownListEventArgs e)
{
try
{
RadGrid1.Rebind();
}
catch
(Exception ex)
{
SPDiagnosticsService.Local.WriteTrace(0,
new
SPDiagnosticsCategory(
"Autoreportlinks error: "
, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace);
}
}
protected
void
RadDropDownMonths_SelectedIndexChanged(
object
sender, DropDownListEventArgs e)
{
try
{
RadGrid1.Rebind();
}
catch
(Exception ex)
{
SPDiagnosticsService.Local.WriteTrace(0,
new
SPDiagnosticsCategory(
"Autoreportlinks error: "
, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace);
}
}
protected
void
RadComboBox1_ItemsRequested(
object
sender, RadComboBoxItemsRequestedEventArgs e)
{
RadComboBox comboBox = (RadComboBox)sender;
comboBox.Items.Clear();
IEnumerable<Year> list = SQL_Misc.GetAll_YearsList();
comboBox.DataSource = list;
//comboBox.DataTextField = "YearNo";
//comboBox.DataValueField = "YearNo";
comboBox.DataBind();
}
#endregion
}
}