Ask a Question related to ASP.NET General, Design and Development.
-
David Foster #1
validating a control created at runtime
Hello,
I have a question regarding validation of a control that I'm creating in an
event handler (the control is not part of the static HTML page). I'm
creating a text box and adding it to a html table like this (all the
AddTextBox method does is create a new textbox and applies the appropriate
styles):
TextBox objTxtNum =
objCommonProcs.AddTextBox(objOneRow[(int)AnswerFields.QuestionId].ToString()
);
responses.Rows[RowIndex].Cells[1].Controls.Add(objTxtNum);
Now, I want to create a validator for this control on the fly:
CompareValidator ValidateTextNumeric = new CompareValidator();
ValidateTextNumeric.ControlToValidate = objTxtNum.ID;
ValidateTextNumeric.Operator = ValidationCompareOperator.DataTypeCheck;
ValidateTextNumeric.Visible = true;
ValidateTextNumeric.Type = ValidationDataType.Integer;
ValidateTextNumeric.Text = "*";
ValidateTextNumeric.ErrorMessage = "Response must be a number.";
Page.Validators.Add( ValidateTextNumeric );
responses.Rows[RowIndex].Cells[1].Controls.Add(ValidateTextNumeric);
Now, adding the validator to the page's validator's collection doesn't seem
to do anything. What I'd expect is to be able to call Page.Validate(), and
then check Page.Is_Valid to know if the page is ok or not. From what I've
read, a validator needs to be added in the Page_Init method, which is
obviously inappropriate for what I'm trying to do. Is there any way to
dynamically add a validator to the page, and have it registered for the
purpose of Page.Is_Valid, or is ther some other way to solve this problem?
Thanks,
Dave
David Foster Guest
-
Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created)
Ok here's my scenario. I have a Custom Composite Server Control (CCSC) consisting of a TextBox, Button & Panel. (And some other code - which I... -
IPostBackDataHandler and validating a control -- the best place to do this.
Hi, I have an asp.net page with two composite controls on it as well as a single button in the asp.net page AND a single dropdown box on the page... -
Adding Validator Control at runtime in a Custom Control
Hi Wim, How do we link the TextBox to this validator control class in runtime ? Could you please tell. Thanks _ Muds. Wim Hollebrandse... -
validating a custom control in a datagrid
hi, i have a datagrid which display custom controls when user clicks edit, changing data. I am using customvalidator to validate this control. I... -
Validating a custom, composite web control
Hi I need to create a custom, composite server control which contains a text box that needs to be validated. I need to be able to add external...



Reply With Quote

