Page_ClientValidate()对象预期的错误,找不到验证程序 [英] Page_ClientValidate() object expected error, cant find the validator
问题描述
我有一个包含一个空的ASP形式HomePage.aspx:面板,一个DropDownList让用户选择一个SPFielType ...索引变了,我的HomePage.aspx.cs页面获取文本选中,将加载的用户控件在面板内,该用户提供的控制将基于由用户和一个按钮调用validateForm()函数所选择的spfieldtype生成控制...我的问题是,validateForm内部)的Page_ClientValidate()函数(不能找到验证程序,我也试过给一个组名,但仍然没有工作。
当林把按钮里面我的aspx页面(不是动态渲染),它是验证我的网页(< ASP:按钮的ID =提交按钮的文本=验证=服务器/>
)。
但是,当林渲染它动态的,不能验证form..This是林试图做的:
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)
{
}
}
//所述CreateFieldRenderingControl()函数将基于由用户选择的参数的字段类型生成控制
// the CreateFieldRenderingControl() function will generate a control based on the argument fieldType chosen by the user.
先谢谢了。
推荐答案
Sharepoint的有一个丑陋的怪癖它可以分配一个GUID是一个控件的ID。我看到这是由SharePoint产生试图使用这些GUID作为变量名的JavaScript。这是没有好 - 它打破了脚本 - 破折号在JavaScript变量名允许的。我怀疑这是您所遇到的问题。而且,我猜罪魁祸首是 this.CreateFieldRenderingControl()
。它看起来像方法生成编号...是标识一个GUID?如果是这样,请尝试使用一些安全覆盖标识,或许只是从该GUID删除划线。
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.
这篇关于Page_ClientValidate()对象预期的错误,找不到验证程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!