Does anyone know what the default validation group name is for contour? I have a custom control I'm adding, but it doesn't seem to be adding the validation group to it's validationgroup setting, so it's not getting fired along with the standard form controls.
Does anyone know how I'd go about setting this? The control I'm adding is the Telerik RadCaptcha one. I know there's the ReCaptcha one, but this is to replace that, as ReCaptcha requires you to authenticate server side to google, and the very strict security on the server prevents this, and changing the security is not an option.
I've figured out a (hacky) way of doing this in the unlikely offchance that this is something anyone else runs into. I just attach an event to the Init event of the RadCaptcha control (any webcontrol should have this event to tap into), and then have the following code to work out what the validationgroup should be:
string validationGroup = ((RadCaptcha)sender).Parent.ClientID; int start = validationGroup.IndexOf("_RenderForm_"); int end = validationGroup.IndexOf("_", start + 12); ((RadCaptcha)sender).ValidationGroup = validationGroup.Substring(0, end);
Basically, get the parent controls' ID, and strip out everything after the macro control to get the macro client id.
Ugh, this is really annoying me. I've created a custom control (dropdownlist with validation), and trying to get it to validate with the contour form. It's just not working very well for me, assumedly because i dont have the right validationGroup set.
I've tried the above code, and various combinations. I've debugged and looked through all the controls being rendered, and can't find anything that even contains "_RenderForm_" in it. Is this supposed to work for the latest version (1.1.3)??
Please, if anybody can help steer me in the right direction, i'll be eternally grateful. I'll happily post my full working code once i'm done, as i have been unable to find a full example outlining how to create a custom fieldset, which renders a custom webcontrol, which contains custom validation. If there is an example out there, a link to that would suffice too.
Hooray, i got this working. Turns out it wasn't the validation group (I didnt even need to set this, since it's the only form on the page).. i just had to override the OnSelectedIndexChanged function, and call the validation from there.
Here's my working code of my custom control if anybody is interested:
public class ValidatedDropdownList : DropDownList
{
private RangeValidator rangeValidator;
public string InvalidMessage;
public string IntroMessage;
public string ClientScript = "true";
protected override void OnInit(EventArgs e)
{
rangeValidator = new RangeValidator();
rangeValidator.MinimumValue = "0";
rangeValidator.MaximumValue = "99999999";
rangeValidator.ControlToValidate = this.ID;
rangeValidator.ErrorMessage = InvalidMessage;
rangeValidator.EnableClientScript = (this.ClientScript.ToLower() != "false");
rangeValidator.IsValid = validateSelectedValue(this.SelectedValue);
Controls.Add(rangeValidator);
}
protected override void OnSelectedIndexChanged(EventArgs e)
{
base.OnSelectedIndexChanged(e);
rangeValidator.IsValid = validateSelectedValue(this.SelectedValue);
}
private bool validateSelectedValue(string inValue)
{
Int32 selectedValue = -5;
bool b = Int32.TryParse(inValue, out selectedValue);
return (b && selectedValue > 0);
}
protected override void Render(HtmlTextWriter w)
{
base.Render(w);
base.RenderChildren(w);
}
/// <summary>
/// Override the CreateControlCollection to overcome the "does not allow child controls".
/// </summary>
/// <returns></returns>
protected override ControlCollection CreateControlCollection()
{
return new ControlCollection(this);
}
}
in my addemailvalidatortoemail method in my Webcontrol i have custom validator that does unique email check on members (got contour registratation form) however the validator does not fire as i dont have contour validationgroup!!
I've done some test and it seems to me that it uses the ID of the render form user control as name of the validation group.
If you add an Event handler to the PreRender event of your validation control you can locate the RenderForm usercontrol (if you have multiple forms on a page you might want to iterate over the parent property until you get the form) and set the validationgroup based on the Id.
Managed to sort this nicely, in fact thanks to your injection suggestion i can get other custom validators injected in to double check email and password entered twice are correct. I managed to get the validation group by using a generic find control like method e.g:
/// <summary>
/// get find control method using generics
/// </summary>
/// <typeparam name="T">type of item you want</typeparam>
/// <param name="ancestor">parent to start looking from</param>
/// <returns>collection of T items</returns>
public static List<T> ControlsByTypeUsingAncestor<T>(Control ancestor) where T : Control
{
var controls = new List<T>();
//Append to search results if we match the type
if (typeof (T).IsAssignableFrom(ancestor.GetType()))
{
controls.Add((T) ancestor);
}
//Recurse into child controls
foreach (Control ctrl in ancestor.Controls)
{
controls.AddRange(ControlsByTypeUsingAncestor<T>(ctrl));
}
return controls;
}
I called it this way to get the validation gruop
string vGroup = string.Empty;
List<RequiredFieldValidator> reqValidators = ExtensionMethods.ControlsByTypeUsingAncestor<RequiredFieldValidator>(this.Page);
var validatorWithGroupSet = (from v in reqValidators
where v.ValidationGroup != string.Empty
select v).FirstOrDefault();
vGroup = validatorWithGroupSet.ValidationGroup;
Default ValidationGroup name?
Hi,
Does anyone know what the default validation group name is for contour? I have a custom control I'm adding, but it doesn't seem to be adding the validation group to it's validationgroup setting, so it's not getting fired along with the standard form controls.
Does anyone know how I'd go about setting this? The control I'm adding is the Telerik RadCaptcha one. I know there's the ReCaptcha one, but this is to replace that, as ReCaptcha requires you to authenticate server side to google, and the very strict security on the server prevents this, and changing the security is not an option.
Cheers,
Tim.
I've figured out a (hacky) way of doing this in the unlikely offchance that this is something anyone else runs into. I just attach an event to the Init event of the RadCaptcha control (any webcontrol should have this event to tap into), and then have the following code to work out what the validationgroup should be:
string validationGroup = ((RadCaptcha)sender).Parent.ClientID;
int start = validationGroup.IndexOf("_RenderForm_");
int end = validationGroup.IndexOf("_", start + 12);
((RadCaptcha)sender).ValidationGroup = validationGroup.Substring(0, end);
Basically, get the parent controls' ID, and strip out everything after the macro control to get the macro client id.
Cheers,
Tim.
Ugh, this is really annoying me. I've created a custom control (dropdownlist with validation), and trying to get it to validate with the contour form. It's just not working very well for me, assumedly because i dont have the right validationGroup set.
I've tried the above code, and various combinations. I've debugged and looked through all the controls being rendered, and can't find anything that even contains "_RenderForm_" in it. Is this supposed to work for the latest version (1.1.3)??
Here's the code i have currently:
Please, if anybody can help steer me in the right direction, i'll be eternally grateful. I'll happily post my full working code once i'm done, as i have been unable to find a full example outlining how to create a custom fieldset, which renders a custom webcontrol, which contains custom validation. If there is an example out there, a link to that would suffice too.
Cheers
Greg
Actually it seems like client side validation is working okay for my control, but when that passes and it posts back, it fails on the server side.
This has me stumped. I'm going to bed before it breaks me completely. :|
I posted a bit more info here btw: http://our.umbraco.org/forum/umbraco-pro/contour/12897-Best-way-to-create-a-lookup-field?p=0#comment47984
Hooray, i got this working. Turns out it wasn't the validation group (I didnt even need to set this, since it's the only form on the page).. i just had to override the OnSelectedIndexChanged function, and call the validation from there.
Here's my working code of my custom control if anybody is interested:
Tim,
I need to get validation group for contour in own custom control the oninit event does not give me sender is there another way i can get it?
I have
in my addemailvalidatortoemail method in my Webcontrol i have custom validator that does unique email check on members (got contour registratation form) however the validator does not fire as i dont have contour validationgroup!!
Regards
Ismail
Ismail,
I've done some test and it seems to me that it uses the ID of the render form user control as name of the validation group.
If you add an Event handler to the PreRender event of your validation control you can locate the RenderForm usercontrol (if you have multiple forms on a page you might want to iterate over the parent property until you get the form) and set the validationgroup based on the Id.
Hope this helps,
Harald
http://harald.ulriksen.net
Harald,
Managed to sort this nicely, in fact thanks to your injection suggestion i can get other custom validators injected in to double check email and password entered twice are correct. I managed to get the validation group by using a generic find control like method e.g:
I called it this way to get the validation gruop
Regards
Ismail
is working on a reply...