admin管理员组文章数量:1277560
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.
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.
Share Improve this question edited May 24, 2011 at 11:31 Grace asked Mar 30, 2011 at 13:00 GraceGrace 1,26521 silver badges48 bronze badges 2- Did you try to debug your js code using browser tools like firebug or Web Developer to see where exactly it is failing. – gbs Commented Mar 30, 2011 at 17:48
- yeah I did.. he cant recognize the validator.. i dono why..i also tried to add the validator on the controls of the SPFIeld but no solution.. – Grace Commented Mar 31, 2011 at 10:04
6 Answers
Reset to default 3Sharepoint 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.
After you loaded the control check the ID control By Firebug or just by see the source of the HTML because there are certain controls that when you put into other controls, their ID change at the rendering. If you can, write the code of the htmnl code also.
try this(pass group name as argument in Page_ClientValidation function)
Page_ClientValidation("group")
Try this:
newValidator.ControlToValidate = fieldRenderingControl.ClientID;
Instead of Page_ClientValidate(), use:
ValidatorValidate("id of field rendering control");
But, in one of your responses, this id is "Field_4a4ab3a1-d5cc-4fbb-a212-ec5697827c75" and this is not a valid client id. Hyphens cannot be used. First, ensure a valid id in client.
Maybe this post is too late... but here are some ideas...
There are several possible things:
(1) The validator and the control to be validated are in the same panel? It is possible that there is a hidden panel while the validation was being done.
(2) If you are creating dynamically, was this creation put on the Page Load? and if so, was created within a function to validate input for the first time? It is possible that it is not necessary to do so.
(3) The use of protected override void CreateChildControls() eventually not runs on all the process of reloading, especially if the ViewState changes in some controls. You can put it in the Page Load.
(4) Other alternative is to place the button inside the Panel, but the visible attribute = false and also the validator, with attribute enabled = false. When you run the action, you change these two States and you can work with the PostBack.
本文标签: cPageClientValidate() object expected errorcant find the validatorStack Overflow
版权声明:本文标题:c# - Page_ClientValidate() object expected error, cant find the validator - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741247964a2365247.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论