Tuesday, July 05, 2011

Using A ValidationSummary Control's ShowMessageBox (kinda) with Telerik Controls in Medium Trust

 I guess there is an issue with Validation Summaries and Telerik Controls.  If your site is running under Medium trust, you can't use the ShowMessageBox and instead you have to use the ShowSummary method.  I noticed this through off the styling of some of my controls once the error summary was rendered so I came up with a work around. Note be careful where you call this code else you will get an error, this worked for me using the FormView_ItemCommand.

ValidationSummary vs =
(ValidationSummary)MyFormView.Row.FindControl ( "myvalidationsummaryname" );
if ( vs != null )
  string sErr = vs.HeaderText  + "\\n";
  for ( int i = 0 ; i < this.Validators.Count ; i++ )
    if ( !this.Validators[ i ].IsValid )
      sErr += "* " + this.Validators[ i ].ErrorMessage + "\\n";
  myRadAjaxManager.ResponseScripts.Add ("alert('" + sErr + "');" );

That should get you going.

No comments: