I have an editor in the edit form of my radgrid which is ajaxified via an AjaxManager on the master page and an AjaxManagerProxy on the content page. I am setting the content property of the editor on the ItemCreated event of the grid. On ItemCommand of the grid I call a save method where I find the editor and get the content from the editor. If I take the AjaxManagerProxy off the page this all works fine but with the proxy on the page the content property of the editor is always empty. I am guessing with ajaxifying the grid the ItemCreated event is being called again overwriting the content property. Any help anyone can provide me on how to "fix" this issue is appreciated. I will post my aspx and .cs pages
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Projects.aspx.cs" Inherits="Projects" %> |
<%@ MasterType VirtualPath="~/MasterPage.master" %> |
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> |
<script type="text/javascript"> |
function onRequestStart(sender, args) { |
if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 || |
args.get_eventTarget().indexOf("ExportToWordButton") >= 0 || |
args.get_eventTarget().indexOf("ExportToPdfButton") >= 0 || |
args.get_eventTarget().indexOf("ExportToCsvButton") >= 0) { |
args.set_enableAjax(false); |
} |
} |
</script> |
<telerik:RadAjaxManagerProxy ID="AjaxManagerProxyProjects" runat="server"> |
<AjaxSettings> |
<telerik:AjaxSetting AjaxControlID="RadGridProjects"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="RadGridProjects" LoadingPanelID="RadAjaxLoadingPanel1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
</AjaxSettings> |
</telerik:RadAjaxManagerProxy> |
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Black" /> |
<telerik:RadGrid ID="RadGridProjects" AllowSorting="True" |
AllowPaging="True" PageSize="50" runat="server" GridLines="None" |
Width="100%" ShowStatusBar="true" AllowFilteringByColumn="true" |
AutoGenerateColumns="false" AllowAutomaticInserts="false" |
AllowAutomaticDeletes="false" AllowAutomaticUpdates="false" |
GroupingSettings-CaseSensitive="false" |
ShowGroupPanel="true" Skin="Black" |
OnPreRender="RadGridProjects_PreRender" |
OnItemCreated="RadGridProjects_ItemCreated" |
OnNeedDataSource="RadGridProjects_NeedDataSource" |
OnItemCommand="RadGridProjects_ItemCommand" |
OnItemDataBound="RadGridProjects_ItemDataBound"> |
<PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle> |
<ExportSettings OpenInNewWindow="true" ExportOnlyData="true" |
Pdf-AllowPrinting="true" Pdf-AllowAdd="true" Pdf-AllowCopy="true" |
Pdf-AllowModify="true" IgnorePaging="true" FileName="Projects" Pdf-PageTitle="Projects" > |
</ExportSettings> |
<MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="ProjectID" |
EditMode="EditForms" AllowMultiColumnSorting="true" TableLayout="Auto" EnableHeaderContextMenu="true"> |
<CommandItemSettings |
AddNewRecordText="Add Project" |
ShowExportToWordButton="true" |
ShowExportToExcelButton="true" |
ShowExportToCsvButton="true" |
ShowExportToPdfButton="true" |
/> |
<Columns> |
<telerik:GridBoundColumn HeaderText="Photographer" UniqueName="Photographer"></telerik:GridBoundColumn> |
<telerik:GridDateTimeColumn DataField="ProjectDate" HeaderText="Date" |
UniqueName="ProjectDate" DataFormatString="{0:d}" PickerType="DatePicker" > |
</telerik:GridDateTimeColumn> |
<telerik:GridBoundColumn DataField="ProjectID" HeaderText="Project ID" UniqueName="ProjectID"></telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="LocationOrEventName" HeaderText="Location/Event Name" UniqueName="LocationEventName"></telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="Volume" HeaderText="Volume" UniqueName="Volume"></telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="SpecialInstructions" HeaderText="Special Instructions" UniqueName="SpecialInstructions"></telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="Notes" HeaderText="Notes" UniqueName="Notes"></telerik:GridBoundColumn> |
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn" ButtonType="ImageButton"> |
<ItemStyle Width="45px" HorizontalAlign="Center" /> |
<HeaderStyle Width="45px" /> |
</telerik:GridEditCommandColumn> |
<telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" |
ConfirmDialogType="RadWindow" |
ConfirmText="Are you sure you want to delete this Project?" |
ConfirmTitle="Product Delete" Text="Delete" UniqueName="DeleteCommandColumn"> |
<ItemStyle HorizontalAlign="Center" Width="45px" /> |
<HeaderStyle Width="45px" /> |
</telerik:GridButtonColumn> |
</Columns> |
<EditFormSettings ColumnNumber="2" EditFormType="Template" CaptionDataField="LocationOrEventName,ProjectID " CaptionFormatString="Edit {0} - {1}"> |
<FormTemplate> |
<table width="100%"> |
<tr> |
<td colspan="2"> |
<asp:ValidationSummary ID="ValidationSummaryProject" runat="server" ValidationGroup="Product" CssClass="failureNotification" /> |
</td> |
</tr> |
<tr> |
<td colspan="2"> |
<asp:Label ID="LabelProjectID" runat="server" Text='ProjectID: <%#Eval ("ProjectID") %>'></asp:Label> |
</td> |
</tr> |
<tr> |
<td> |
<span class="requiredFldInd">*</span>Photographer: |
</td> |
<td> |
<telerik:RadComboBox ID="RadComboBoxPhotographer" runat="server" |
DataTextField="FullName" DataValueField="PhotographerID" Skin="Black" OnDataBound="ComboBoxPhotographer_DataBound"> |
</telerik:RadComboBox> |
<asp:RequiredFieldValidator ID="RequiredFieldValidatorPhotographer" runat="server" ControlToValidate="RadComboBoxPhotographer" |
ErrorMessage="Photographer is required." ToolTip="Photographer is required." ValidationGroup="Project">*</asp:RequiredFieldValidator> |
</td> |
</tr> |
<tr> |
<td><span class="requiredFldInd">*</span>Location/Event Name:</td> |
<td> |
<asp:TextBox ID="TextBoxLocationEventName" runat="server" Text='<%#Eval("LocationOrEventName") %>'></asp:TextBox> |
<asp:RequiredFieldValidator ID="RequiredFieldValidatorName" runat="server" ControlToValidate="TextBoxLocationEventName" |
ErrorMessage="Location/Event Name is required." ToolTip="Location/Event Name is required." ValidationGroup="Project">*</asp:RequiredFieldValidator> |
</td> |
</tr> |
<tr> |
<td><span class="requiredFldInd">*</span>Date:</td> |
<td> |
<telerik:RadDatePicker ID="DatePickerProjectDate" runat="server" Skin="Black" |
Culture="English (United States)" ShowPopupOnFocus="true" EnableScreenBoundaryDetection="true" |
PopupDirection="BottomRight" ShowAnimation-Type="Fade" |
SelectedDate='<%#(Eval("ProjectDate") is DBNull ?DateTime.Today:Eval("ProjectDate")) %>' MinDate="1/1/1900"> |
<Calendar> |
<SpecialDays> |
<telerik:RadCalendarDay Repeatable="Today" ItemStyle-CssClass="rcToday" /> |
</SpecialDays> |
</Calendar> |
</telerik:RadDatePicker> |
<asp:RequiredFieldValidator ID="RequiredFieldProjectDate" runat="server" |
ControlToValidate="DatePickerProjectDate" |
ErrorMessage="Project Date is required" |
ValidationGroup="Project">*</asp:RequiredFieldValidator> |
</td> |
</tr> |
<tr> |
<td>Volume:</td> |
<td> |
<asp:TextBox ID="TextBoxVolume" runat="server" Text='<%#Eval("Volume") %>'></asp:TextBox> |
</td> |
</tr> |
<tr> |
<td valign="top">Special Instructions:</td> |
<td> |
<telerik:RadEditor ID="RadEditorInstructions" runat="server" ToolsWidth="450px" Height="250px" Width="495px" |
EditModes="Design" |
ToolsFile="~/App_Data/Tools.xml" |
ContentFilters="FixUlBoldItalic, MozEmStrong, ConvertFontToSpan, ConvertToXhtml, FixEnclosingP" |
Skin="Black"> |
<CssFiles> |
<telerik:EditorCssFile Value="~/App_Themes/EditorContentAreaStyles.css" /> |
</CssFiles> |
</telerik:RadEditor> |
</td> |
</tr> |
<tr> |
<td valign="top">Notes:</td> |
<td> |
<telerik:RadEditor ID="RadEditorNotes" runat="server" ToolsWidth="450px" Height="250px" Width="495px" |
EditModes="Design" ToolbarMode="ShowOnFocus" |
ToolsFile="~/App_Data/Tools.xml" |
ContentFilters="FixUlBoldItalic, MozEmStrong, ConvertFontToSpan, ConvertToXhtml, FixEnclosingP" |
Skin="Black"> |
<CssFiles> |
<telerik:EditorCssFile Value="~/App_Themes/EditorContentAreaStyles.css" /> |
</CssFiles> |
</telerik:RadEditor> |
</td> |
</tr> |
<tr> |
<td align="right" colspan="2"> |
<asp:Button ID="ButtonProjectSave" runat="server" UseSubmitBehavior="false" |
Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' |
CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' ValidationGroup="Project"> |
</asp:Button> |
|
<asp:Button ID="ButtonProjectCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"> |
</asp:Button> |
</td> |
</tr> |
</table> |
</FormTemplate> |
</EditFormSettings> |
</MasterTableView> |
<ClientSettings AllowDragToGroup="true" AllowAutoScrollOnDragDrop="true" |
AllowColumnHide="true" AllowColumnsReorder="true" AllowExpandCollapse="true" |
AllowGroupExpandCollapse="true" Resizing-AllowColumnResize="true"> |
</ClientSettings> |
</telerik:RadGrid> |
</asp:Content> |
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Web; |
using System.Web.UI; |
using System.Web.UI.WebControls; |
using System.Web.UI.HtmlControls; |
using System.Configuration; |
using AgriGraphicsLibrary.Business; |
using AgriGraphicsLibrary.Entity; |
using Sundial.Core.BusinessDataEntities; |
using Telerik.Web.UI; |
public partial class Projects : SundialBasePage |
{ |
bool isPDFExport = false; |
private class PageSessionVariables |
{ |
public const string ProjectList = "ITSProjects.ProjectList"; |
public const string CurrentProject = "ITSProjects.CurrentProject"; |
public const string UserPhotographer = "ITSProjects.UserPhotographer"; |
} |
#region Attributes |
#endregion |
#region Properties |
private List<ProjectEntity> ProjectList |
{ |
get |
{ |
List<ProjectEntity> projects = new List<ProjectEntity>(); |
if (Session[PageSessionVariables.ProjectList] != null) |
{ |
projects = (List<ProjectEntity>)Session[PageSessionVariables.ProjectList]; |
} |
else |
{ |
if (AGContext.IsUserPhotographer) |
{ |
projects = ProjectBL.GetByPhotographerID(this.UserPhotographer.PhotographerID); |
} |
else |
{ |
projects = ProjectBL.GetAll(ActiveFlagEnum.Active); |
} |
Session[PageSessionVariables.ProjectList] = projects; |
} |
return projects; |
} |
set |
{ |
Session[PageSessionVariables.ProjectList] = value; |
} |
} |
private PhotographerEntity UserPhotographer |
{ |
get |
{ |
PhotographerEntity photographer = new PhotographerEntity(); |
if (Session[PageSessionVariables.UserPhotographer] != null) |
{ |
photographer = (PhotographerEntity)Session[PageSessionVariables.UserPhotographer]; |
} |
return photographer; |
} |
set |
{ |
Session[PageSessionVariables.UserPhotographer] = value; |
} |
} |
private ProjectEntity CurrentProject |
{ |
get |
{ |
ProjectEntity project = new ProjectEntity(); |
if (Session[PageSessionVariables.CurrentProject] != null) |
{ |
project = (ProjectEntity)Session[PageSessionVariables.CurrentProject]; |
} |
return project; |
} |
set |
{ |
Session[PageSessionVariables.CurrentProject] = value; |
} |
} |
#endregion |
#region Page Events |
protected void Page_Load(object sender, EventArgs e) |
{ |
RadAjaxManager manager = RadAjaxManager.GetCurrent(Page); |
manager.ClientEvents.OnRequestStart = "onRequestStart"; |
SetPagePermissions(); |
if (!IsPostBack) |
{ |
ClearSessions(); |
} |
} |
protected void RadGridProjects_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) |
{ |
if (!e.IsFromDetailTable) |
{ |
RadGridProjects.DataSource = this.ProjectList; |
} |
} |
protected void RadGridProjects_ItemCommand(object source, GridCommandEventArgs e) |
{ |
GridEditableItem editedItem = e.Item as GridEditableItem; |
switch (e.CommandName) |
{ |
case RadGrid.EditCommandName: |
{ |
//get the id from the record we are editing |
//read the entity |
this.CurrentProject = ProjectBL.Read((Int64)editedItem.GetDataKeyValue("ProjectID")); |
break; |
} |
case RadGrid.InitInsertCommandName: |
{ |
//set to a new entity |
this.CurrentProject = new ProjectEntity(); |
break; |
} |
case RadGrid.UpdateCommandName: |
{ |
if (IsValid) |
{ |
try |
{ |
SaveProject(editedItem); |
//clear the session variable so it gets the new information |
Session[PageSessionVariables.ProjectList] = null; |
} |
catch (Exception ex) |
{ |
throw ex; |
} |
} |
break; |
} |
case RadGrid.PerformInsertCommandName: |
{ |
if (IsValid) |
{ |
try |
{ |
SaveProject(editedItem); |
//clear the session variable so it gets the new information |
Session[PageSessionVariables.ProjectList] = null; |
} |
catch (Exception ex) |
{ |
throw ex; |
} |
} |
break; |
} |
case RadGrid.RebindGridCommandName: |
{ |
//clear the session variable so it gets the new information |
Session[PageSessionVariables.ProjectList] = null; |
break; |
} |
case RadGrid.DeleteCommandName: |
{ |
//delete the project |
ProductBL.Delete((Int64)editedItem.GetDataKeyValue("ProductID"), AGContext.UserInfo.UserID.ToString()); |
//clear the session variable so it gets the new information |
Session[PageSessionVariables.ProjectList] = null; |
break; |
} |
case RadGrid.ExportToPdfCommandName: |
{ |
isPDFExport = true; |
//RadGridProducts.ExportSettings.Pdf.PageHeight = Unit.Parse("210mm"); |
//RadGridProducts.ExportSettings.Pdf.PageWidth = Unit.Parse("297mm"); |
RadGridProjects.ExportSettings.Pdf.PageLeftMargin = Unit.Parse("1mm"); |
RadGridProjects.ExportSettings.Pdf.PageRightMargin = Unit.Parse("1mm"); |
RadGridProjects.ExportSettings.Pdf.PageHeaderMargin = Unit.Parse("10mm"); |
RadGridProjects.ExportSettings.Pdf.PageFooterMargin = Unit.Parse("10mm"); |
//RadGridProducts.MasterTableView.GetColumn("Email").HeaderStyle.Width = Unit.Pixel(200); |
break; |
} |
} |
} |
protected void RadGridProjects_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem) |
{ |
GridDataItem item = e.Item as GridDataItem; |
ProjectEntity entity = (ProjectEntity)e.Item.DataItem; |
List<ImageEntity> images = ImageBL.GetByProjectID(entity.ProjectID); |
PhotographerDisplayEntity pde = PhotographerDisplayBL.GetByPhotographerID(entity.PhotographerID); |
item["Photographer"].Text = pde.FullName; |
//if there are images associated with this project you can't delete it |
if (images.Count > 0) |
{ |
item["DeleteCommandColumn"].Controls[0].Visible = false; |
} |
} |
} |
protected void RadGridProjects_PreRender(object sender, EventArgs e) |
{ |
foreach (GridColumn col in RadGridProjects.MasterTableView.Columns) |
{ |
if (col.UniqueName == "EditCommandColumn") |
{ |
col.Visible = ApplicationFeature.GetPermission(AGContext.UserInfo.PersonID, ApplicationFeature.Projects).CanUpdate; |
} |
if (col.UniqueName == "DeleteCommandColumn") |
{ |
col.Visible = ApplicationFeature.GetPermission(AGContext.UserInfo.PersonID, ApplicationFeature.Projects).CanDelete; |
} |
} |
} |
protected void RadGridProjects_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) |
{ |
if (isPDFExport) |
FormatItem(e.Item); |
if (e.Item is GridCommandItem) |
{ |
//get the add button/image |
LinkButton addButton = (LinkButton)e.Item.FindControl("InitInsertButton"); |
Button addImage = (Button)e.Item.FindControl("AddNewRecordButton"); |
//hide the button/image if they don't have the feature |
addButton.Visible = ApplicationFeature.GetPermission(AGContext.UserInfo.PersonID, ApplicationFeature.Projects).CanCreate; |
addImage.Visible = ApplicationFeature.GetPermission(AGContext.UserInfo.PersonID, ApplicationFeature.Projects).CanCreate; |
} |
if ((e.Item is GridEditFormItem) && e.Item.IsInEditMode) |
{ |
GridEditFormItem editItem = (GridEditFormItem)e.Item; |
ProjectEntity pe = this.CurrentProject; |
RadComboBox cb = (RadComboBox)editItem.FindControl("RadComboBoxPhotographer"); |
RadEditor resi = (RadEditor)editItem.FindControl("RadEditorInstructions"); |
RadEditor ren = (RadEditor)editItem.FindControl("RadEditorNotes"); |
Label lb = (Label)editItem.FindControl("LabelProjectID"); |
cb.DataSource = PhotographerDisplayBL.GetAll(ActiveFlagEnum.Active); |
cb.DataBind(); |
resi.Content = pe.SpecialInstructions; |
ren.Content = pe.Notes; |
if (AGContext.IsUserPhotographer) |
{ |
cb.SelectedValue = this.UserPhotographer.PhotographerID.ToString(); |
cb.Enabled = false; |
if (editItem.OwnerTableView.IsItemInserted) |
{ |
lb.Visible = false; |
} |
} |
else |
{ |
if (!editItem.OwnerTableView.IsItemInserted) |
{ |
if (pe.ProjectID != ProjectEntity.ProjectIDDefault) |
{ |
cb.SelectedValue = pe.PhotographerID.ToString(); |
} |
else |
{ |
cb.SelectedValue = "-1"; |
} |
} |
else |
{ |
lb.Visible = false; |
} |
} |
} |
} |
protected void ComboBoxPhotographer_DataBound(object sender, EventArgs e) |
{ |
RadComboBox cb = (RadComboBox)sender; |
cb.Items.Insert(0, new RadComboBoxItem("Select One....", "-1")); |
} |
#endregion |
#region Load Data |
#endregion |
#region Save Data |
private void SaveProject(GridEditableItem editItem) |
{ |
ProjectEntity entity = this.CurrentProject; |
entity.LocationOrEventName = ((editItem.FindControl("TextBoxLocationEventName") as TextBox).Text); |
RadEditor ren = editItem.FindControl("RadEditorNotes") as RadEditor; |
entity.Notes = ren.Content; |
entity.PhotographerID = Convert.ToInt64((editItem.FindControl("RadComboBoxPhotographer") as RadComboBox).SelectedValue); |
entity.ProjectDate = (DateTime)(editItem.FindControl("DatePickerProjectDate") as RadDatePicker).SelectedDate; |
entity.SpecialInstructions = (editItem.FindControl("RadEditorInstructions") as RadEditor).Content; |
entity.Volume = ((editItem.FindControl("TextBoxVolume") as TextBox).Text); |
entity.ModifiedBy = AGContext.UserInfo.UserID.ToString(); |
ProjectBL.Update(entity); |
} |
#endregion |
#region Custom Code |
private void SetPagePermissions() |
{ |
VerifyPageAccess(AGContext.UserInfo.PersonID, ApplicationFeature.Projects); |
} |
private void SetControlPermissions() |
{ |
} |
private void ClearSessions() |
{ |
Session[PageSessionVariables.ProjectList] = null; |
Session[PageSessionVariables.CurrentProject] = null; |
Session[PageSessionVariables.UserPhotographer] = null; |
} |
private void RebindGrids() |
{ |
} |
private void FormatItem(GridItem gridItem) |
{ |
foreach (TableCell cell in gridItem.Cells) |
{ |
cell.Style["font-family"] = "Arial Narrow"; |
cell.Style["font-size"] = "12pt"; |
//cell.Width = Unit.Parse("300px"); |
} |
switch (gridItem.ItemType) |
{ |
//case GridItemType.Item: gridItem.Style["background-color"] = "#9999ff"; break; |
//case GridItemType.AlternatingItem: gridItem.Style["background-color"] = "#ccccff"; break; |
//case GridItemType.Header: gridItem.Style["background-color"] = "#aaa"; break; |
} |
} |
#endregion |
} |