Add a required authentication module to the SharePoint Web Part

I am writing a webpart for MOSS 2007. I need to check the text field in this web part or use the required field validation module.

I create the required field validator as follows:

vldProjectError = new RequiredFieldValidator();
vldProjectError.ForeColor = Color.Red;
vldProjectError.ErrorMessage = Resources.LABEL_PROJECT_ERROR;
vldProjectError.ControlToValidate = txtProjectName.ClientID;
vldProjectError.Display = ValidatorDisplay.Dynamic;
this.Controls.Add(vldProjectError);

The above code snippet is in the override of CreateChildControls (). When I open this web page page, I get a general error message in SharePoint. I can not catch the error by debugging.

I noticed that an exception is thrown after CreateChildControls () and before the Render () method, since the debugger never introduces the Render () method

Any idea on using validators on sharepoint websites? Is there something I can't see?

+3
4

.

txtProjectName.ID = "txtProjectName";    
vldProjectError.ControlToValidate = txtProjectName.ID;

vldProjectError.ControlToValidate = txtProjectName.ClientID;

CreateChidControls().

+3

:

  • , , SharePoint, , .
  • ControlToValidate Render, CreateChildControls. , , txtProjectName .
+2

web.config? , .

0

I had the same problem as you have with the validation elements. The controlId property of the control being checked is zero until you add it to the web part control collection. Thus, the validator should be configured after this line:

this.Controls.Add(txtProjectName);

Check this debugging of your web part and look at the ClientId property of the checked control.

0
source

Source: https://habr.com/ru/post/1705264/