I needed to get validation working with the Notification control so thought i'd share this code, it's taken from http://demos.telerik.com/aspnet-ajax/notification/examples/waiariasupport/defaultcs.aspx but modified to allow multiple ValidationGroups per page
Simply create a UserControl called Validation.ascx and add this markup
and this code-behind
Now add the control to your page in place of a ValidationSummary
You then need to attach the onclick event of the button firing validation to Validation.ValidationJsFunction eg
Simply create a UserControl called Validation.ascx and add this markup
<
telerik:RadNotification
ID
=
"ValidationNotification"
runat
=
"server"
AutoCloseDelay
=
"20000"
EnableRoundedCorners
=
"true"
EnableShadow
=
"true"
KeepOnMouseOver
=
"true"
Position
=
"Center"
Title
=
"Validation errors"
TitleIcon
=
"warning"
ShowCloseButton
=
"true"
Width
=
"350"
>
<
NotificationMenu
Visible
=
"false"
/>
<
ContentTemplate
>
<
asp:ValidationSummary
ID
=
"ValidationSummary"
runat
=
"server"
DisplayMode
=
"BulletList"
ShowMessageBox
=
"false"
ShowSummary
=
"true"
/>
</
ContentTemplate
>
</
telerik:RadNotification
>
and this code-behind
/// <summary>
/// Provides a ValidationSummary inside a Telerik Notification
/// </summary>
/// <example>
/// Add the controls to the page
/// <code><uc1:Validation runat="server" id="Validation" ValidationGroup="Activate" /></code>
///
/// Attach the validation function to the button which fires the validation in OnInit
/// <code>ActivateButton.OnClientClicked = Validation.ValidationJsFunction;</code>
///
/// Any Server-Side validation function will need to show the notification
/// <code>if (!valid) { Validation.ValidationNotificationControl.Show(); }</code>
/// </example>
public
partial
class
Validation : System.Web.UI.UserControl
{
public
string
ValidationGroup {
get
;
set
; }
public
RadNotification ValidationNotificationControl {
get
{
return
this
.ValidationNotification; } }
public
string
ValidationJsFunction {
get
{
return
string
.Format(
"Show_{0}"
, ValidationNotification.ClientID); } }
protected
void
Page_Load(
object
sender, EventArgs e) { }
protected
override
void
OnInit(EventArgs e)
{
ValidationSummary.ValidationGroup = ValidationGroup;
ValidationNotification.OnClientShowing =
string
.Format(
"Check_{0}"
, ValidationSummary.ClientID);
StringBuilder js =
new
StringBuilder();
// the Show function needs to be added to each button which causes validation
js.AppendFormat(
" function Show_{0}()"
, ValidationNotification.ClientID);
js.Append(
" {"
);
js.AppendFormat(
" var notification = $find('{0}');"
, ValidationNotification.ClientID);
js.Append(
" setTimeout(function () { notification.show(); }, 0);"
);
js.Append(
" }"
);
js.AppendFormat(
" function Check_{0}(sender, args)"
, ValidationSummary.ClientID);
js.Append(
" {"
);
js.AppendFormat(
" var summaryElem = document.getElementById('{0}');"
, ValidationSummary.ClientID);
js.Append(
" var noErrors = summaryElem.style.display == 'none';"
);
js.Append(
" args.set_cancel(noErrors);"
);
js.Append(
" }"
);
ScriptManager.RegisterClientScriptBlock(Page,
this
.GetType(), ValidationNotification.ClientID, js.ToString(),
true
);
base
.OnInit(e);
}
}
Now add the control to your page in place of a ValidationSummary
<uc1
:Validation
runat
=
"server"
ID
=
"Validation"
ValidationGroup
=
"Subscription"
/>
You then need to attach the onclick event of the button firing validation to Validation.ValidationJsFunction eg
GetQuoteButton.OnClientClicked = Validation.ValidationJsFunction;