I have a RadGrid with the EditFormSettings set to WebUserControl. Within the WebUserControl I have a CustomValidator, when I run the update command from the WebUserControl page the CustomValidator is run, but does not stop the page from processing. I am checking for Page.IsValid on my RadGrid_ItemCommand.
Page.aspx
Page .aspx.cs
WebUserControl ascx
WebUserControl ascx.cs
Page.aspx
<
telerik:RadGrid
ID
=
"rgSiteContent"
runat
=
"server"
CellSpacing
=
"0"
GridLines
=
"None"
AllowPaging
=
"True"
AllowSorting
=
"True"
AutoGenerateColumns
=
"False"
onneeddatasource
=
"rgSiteContent_NeedDataSource"
onitemcommand
=
"rgSiteContent_ItemCommand"
>
<
MasterTableView
CommandItemDisplay
=
"Top"
DataKeyNames
=
"pageid"
>
<
Columns
>
<
telerik:GridTemplateColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
Groupable
=
"False"
UniqueName
=
"EditCommandColumn"
HeaderText
=
"Actions"
>
<
EditItemTemplate
>
<
telerik:RadButton
runat
=
"server"
CommandName
=
"Update"
Text
=
"Update"
/>
<
telerik:RadButton
runat
=
"server"
CausesValidation
=
"false"
CommandName
=
"Cancel"
Text
=
"Cancel"
/>
</
EditItemTemplate
>
<
ItemTemplate
>
<
telerik:RadButton
runat
=
"server"
CausesValidation
=
"false"
CommandName
=
"Edit"
Text
=
"Edit"
/>
<
telerik:RadButton
runat
=
"server"
CausesValidation
=
"false"
CommandName
=
"Delete"
Text
=
"Delete"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"title"
FilterControlAltText
=
"Filter title column"
HeaderText
=
"Page Title"
ReadOnly
=
"True"
SortExpression
=
"title"
UniqueName
=
"title"
/>
<
telerik:GridBoundColumn
DataField
=
"metadesc"
FilterControlAltText
=
"Filter metadesc column"
HeaderText
=
"Meta Description"
ReadOnly
=
"True"
SortExpression
=
"metadesc"
UniqueName
=
"metadesc"
/>
<
telerik:GridBoundColumn
DataField
=
"metaword"
FilterControlAltText
=
"Filter metaword column"
HeaderText
=
"Meta Keywords"
ReadOnly
=
"True"
SortExpression
=
"metaword"
UniqueName
=
"metaword"
/>
<
telerik:GridHyperLinkColumn
FilterControlAltText
=
"Filter pagelink column"
HeaderText
=
"Page Link"
SortExpression
=
"pagelink"
UniqueName
=
"pagelink"
DataTextField
=
"pagelink"
Target
=
"_blank"
DataNavigateUrlFields
=
"pagelink"
/>
<
telerik:GridBoundColumn
DataField
=
"created"
DataType
=
"System.DateTime"
FilterControlAltText
=
"Filter created column"
HeaderText
=
"Created"
ReadOnly
=
"True"
SortExpression
=
"created"
UniqueName
=
"created"
/>
<
telerik:GridBoundColumn
DataField
=
"lastedit"
DataType
=
"System.DateTime"
FilterControlAltText
=
"Filter lastedit column"
HeaderText
=
"Last Edit"
ReadOnly
=
"True"
SortExpression
=
"lastedit"
UniqueName
=
"lastedit"
/>
<
telerik:GridBoundColumn
DataField
=
"fullname"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter fullname column"
HeaderText
=
"Edited By"
ReadOnly
=
"True"
SortExpression
=
"fullname"
UniqueName
=
"fullname"
/>
</
Columns
>
<
EditFormSettings
EditFormType
=
"WebUserControl"
UserControlName
=
"~/managers/controls/admin_sitecontent_editor.ascx"
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
></
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
</
telerik:RadGrid
>
Page .aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
}
protected void rgSiteContent_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
getSiteContent();
}
protected void getSiteContent()
{
using (SiteDataContext DB = new SiteDataContext())
{
var rsSiteContent = from rs in DB.contents
where rs.parentid == 0
select new
{
pageid = rs.pageid,
pagelink = String.Format("http://www.mysite.com/site/{0}", rs.pagename),
pagename = rs.pagename,
title = rs.title,
metadesc = rs.metadesc,
metaword = rs.metaword,
created = rs.created,
lastedit = rs.lastedit,
fullname = String.Format("{0} {1}", rs.tbl_user.firstname, rs.tbl_user.lastname),
pagecontent = rs.pagecontent
};
rgSiteContent.DataSource = rsSiteContent.ToList();
}
}
protected void rgSiteContent_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.UpdateCommandName)
{
GridEditFormItem editForm = (GridEditFormItem)e.Item;
UserControl userControl = (UserControl)editForm.FindControl(GridEditFormItem.EditFormUserControlID);
if (Page.IsValid)
{
using (SiteDataContext DB = new SiteDataContext())
{
var rsSiteContent = (from rs in DB.contents where rs.pageid == Convert.ToInt32(editForm.GetDataKeyValue("pageid")) select rs).SingleOrDefault();
rsSiteContent.pagename = ((RadTextBox)userControl.FindControl("pagelinkTextBox")).Text;
rsSiteContent.title = ((RadTextBox)userControl.FindControl("pagetitleTextBox")).Text;
rsSiteContent.pagecontent = (((RadEditor)userControl.FindControl("contentEditor"))).Content;
rsSiteContent.metadesc = ((RadTextBox)userControl.FindControl("metadescTextBox")).Text;
rsSiteContent.metaword = ((RadTextBox)userControl.FindControl("metawordTextBox")).Text;
rsSiteContent.lastedit = DateTime.Now;
rsSiteContent.editby = Profile.UserID;
DB.SubmitChanges();
}
}
}
}
WebUserControl ascx
<
asp:CustomValidator
ID
=
"editcontentCustomValidator"
runat
=
"server"
ControlToValidate
=
"pagetitleTextBox"
ValidationGroup
=
"editcontentValidationGroup"
onservervalidate
=
"editcontentCustomValidator_ServerValidate"
Font-Bold
=
"true"
ForeColor
=
"Red"
ValidateEmptyText
=
"true"
/>
<
table
style
=
"width:100%;"
>
<
tr
>
<
td
colspan
=
"2"
>
<
telerik:RadButton
runat
=
"server"
CommandName
=
"Update"
CausesValidation
=
"true"
Text
=
"Save"
ValidationGroup
=
"editcontentValidationGroup"
/>
<
telerik:RadButton
runat
=
"server"
CommandName
=
"Cancel"
CausesValidation
=
"false"
Text
=
"Cancel"
/>
</
td
>
</
tr
>
<
tr
>
<
td
style
=
"width:110px;"
>Page Link:</
td
>
<
td
><
telerik:RadTextBox
ID
=
"pagelinkTextBox"
Runat
=
"server"
Text='<%# DataBinder.Eval(Container, "DataItem.pagename") %>' Width="800px" /></
td
>
</
tr
>
<
tr
>
<
td
style
=
"width:110px;"
>Page Title:</
td
>
<
td
><
telerik:RadTextBox
ID
=
"pagetitleTextBox"
Runat
=
"server"
Text='<%# DataBinder.Eval(Container, "DataItem.title") %>' Width="800px" /></
td
>
</
tr
>
<
tr
>
<
td
style
=
"width:110px;"
>Meta Description:</
td
>
<
td
><
telerik:RadTextBox
ID
=
"metadescTextBox"
Runat
=
"server"
Text='<%# DataBinder.Eval(Container, "DataItem.metadesc") %>' Width="800px" /></
td
>
</
tr
>
<
tr
>
<
td
style
=
"width:110px;"
>Meta Keywords:</
td
>
<
td
><
telerik:RadTextBox
ID
=
"metawordTextBox"
Runat
=
"server"
Text='<%# DataBinder.Eval(Container, "DataItem.metaword") %>' Width="800px" /></
td
>
</
tr
>
<
tr
>
<
td
colspan
=
"2"
>Page Content:</
td
>
</
tr
>
<
tr
>
<
td
colspan
=
"2"
>
<
telerik:RadEditor
ID
=
"contentEditor"
Runat
=
"server"
Width
=
"940px"
Content='<%# DataBinder.Eval(Container, "DataItem.pagecontent") %>' ContentAreaCssFile="~/Styles/RadEditor.css" ContentAreaMode="Div" Height="800px" NewLineMode="Br" />
</
td
>
</
tr
>
</
table
>
WebUserControl ascx.cs
protected void Page_Load(object sender, EventArgs e)
{
}
protected void editcontentCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
List<
string
> strErrors = new List<
string
>();
if (pagelinkTextBox.Text.Count() > 0)
{
using (SiteDataContext DB = new SiteDataContext())
{
var rsCheckDupPageName = from rs in DB.contents where rs.pagename == pagelinkTextBox.Text select rs;
if (rsCheckDupPageName.Count() > 1)
{
strErrors.Add("Duplicate Page Links are not allowed.");
}
}
}
else
{
strErrors.Add("Page Link is required.");
}
if (pagetitleTextBox.Text.Count() <= 0)
{
strErrors.Add("Page Title is required.");
}
if (metadescTextBox.Text.Count() <= 0)
{
strErrors.Add("Meta Description is required.");
}
if (metawordTextBox.Text.Count() <= 0)
{
strErrors.Add("Meta Keywords are required.");
}
if (contentEditor.Text.Count() <= 0)
{
strErrors.Add("Page Content is required.");
}
if (strErrors.Count() > 0)
{
string strErrorMessage = String.Empty;
foreach (string errors in strErrors)
{
strErrorMessage = String.Format("{0}<
br
/>", errors);
}
editcontentCustomValidator.IsValid = false;
editcontentCustomValidator.ErrorMessage = strErrorMessage;
}
}