473,320 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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
Nov 17 '05 #1
1 3465
Hi David.
I have the same problem. Did you find a solution to add runtime controls with validators?

Thanks,
BenHur73.



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
Jul 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andrei Pociu | last post by:
Inside a method some controls are created at runtime. I added an event handler to one of these controls: tracker.Scroll += new System.EventHandler(this.tracker_Scroll); So in the event handler...
6
by: Alex Bink | last post by:
Hi, I have a validating event on a textbox in which I want to prevent the user to leave the textbox without entering the right data. Only if he clicks on another specific control he is allowed...
3
by: Eric | last post by:
I have built a composite user web control that I want to create dynamically. The form will contain a variable number of these controls and as well some of the contents of the user web control...
2
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
7
by: Bruce HS | last post by:
I'd like to call my ancestor Validation Function every time any control on a Win Form generates a Validating or Validated event. I'm using VB. I've extended Textbox, for instance, to have its...
5
by: Ryan | last post by:
A binding navigator control adds the following code for when the Save button is clicked: Me.Validate() Me.UserBindingSource.EndEdit() Me.UserTableAdapter.Update(Me.UserDataSet.User)" You can...
5
by: Guillaume BRAUX | last post by:
Hello, What I want to do is to add a userControl to a form class witch is a different class from the one the button is generated. For example, I want to instanciate a label in "class1" and add...
7
by: mc | last post by:
I've not been able to get a Check box to client side validated on postback. with my changes I can get it to work on the serverside ok but not on the client. I have created a new control as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.