I have a form HomePage.aspx containing an empty asp:Panel, a dropdownlist letting the user pick an SPFielType... on index changed, my HomePage.aspx.cs page will get the text selected and will load a user control inside the panel, this user control will generate a control based on the spfieldtype chosen by the user and a button calling the validateForm() function... my problem is that the Page_ClientValidate() function inside the validateForm() cant find the validator, i also tried to give a groupname but still not working.
When Im putting the button inside my aspx page (not rendering dynamically) it is validating my page.( <asp:Button ID="submitbutton" Text="Validate" runat="server" />
).
But when Im rendering it dynamically , cant validate the form..This is what Im trying to do:
protected override void CreateChildControls()
{
try
{
fieldRenderingControl = this.CreateFieldRenderingControl(this.FieldType);
this.Controls.Add(fieldRenderingControl);
Button button = new Button();
button.UseSubmitBehavior = false;
button.Text = "ValidateButton";
button.ID = "ValidateButton";
button.OnClientClick = "validateForm()";
this.Controls.Add(button);
RequiredFieldValidator newValidator = new RequiredFieldValidator();
newValidator.Text = "***";
newValidator.ID = "valideee";
newValidator.EnableClientScript = true;
newValidator.Enabled = true;
newValidator.SetFocusOnError = true;
newValidator.Display = ValidatorDisplay.Dynamic;
newValidator.ControlToValidate = fieldRenderingControl.ID;
this.Controls.Add(newValidator);
}
catch (Exception ex)
{
}
}
// the CreateFieldRenderingControl() function will generate a control based on the argument fieldType chosen by the user.
thanks in advance.
Sharepoint has an ugly quirk where it can assign a Guid to be the id of a control. I've seen JavaScript that was generated by Sharepoint trying to use these Guids as variable names. This is no good - it breaks scripts - dashes aren't allowed in JavaScript variable names. I suspect this is the problem you are experiencing. And, I'd guess the culprit is this.CreateFieldRenderingControl()
. It looks like that method is generating an Id... is that Id a Guid? If so, try to overwrite the Id with something safe, perhaps just remove the dashes from the Guid.
fieldRenderingControl.ID.Replace("-", "");
If this isn't the exact solution, hopefully it's enough to get you pointed in the right direction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With