473,320 Members | 2,006 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.

Dissapearin Validators

I create controls and validators dynamically dependent on data at runtime.
I create the control then the relevant validator(s) for it assigning the Control.ID as the control to validate.
These controls and validators are then added to a table for display to the user.
This code did seem to work originally, but now does not amd I am stumped as to why. There have been some code

changes, but not to the methods below and I have pretty much undone all these changes but to no avail.
I assume that the ID I pass will be prefixed with the correct naming container when the User Control the objects

live on is rendered with the page as I don't have a could not find code to validate message. The validator is

simply not appearing at the client side.
I can see the space I put in the cell which contains the validator (see in code) and obviously the cell exists

also. But no validator.

Any help on this would be appreciated.

Cheers

Tom

This is the code below------
/// <summary>
/// Create the required control, validator etc for the parameter
/// </summary>
/// <param name="parameter">The parameter info</param>
private void CreateControl( FunctionParameter parameter, int index )
{
// Get the display name
string displayName = parameter.DisplayName;

// Get the control Id
string controlId = parameter.DataName;

// Create the return value
WebControl theControl = null;

// Create an array of BaseValidators to add to
ArrayList validators = new ArrayList( );

// if the control isn't visible store the required default value
if( !parameter.Visible )
{
// Create a text box to store the default value in
TextBox defaultTextBox = new TextBox( );

// get the default value for this control
if(parameter.Value != null)
defaultTextBox.Text = parameter.Value.ToString();
// hide the textbox
defaultTextBox.Visible = false;
theControl = defaultTextBox;
}

// Create the correct input control
else
{
// Check if this parameter has a list of predefined values
if( (string)parameter.PredefinedValues != "NotSet" )
{
// If we have a list of predefined values we need a list box
DropDownList dropDownList = new DropDownList( );
dropDownList.DataSource = GetListItems( (string)parameter.PredefinedValues

);
dropDownList.DataTextField = "DisplayValue";
dropDownList.DataValueField = "StoredProcValue";
dropDownList.DataBind( );
theControl = dropDownList;
}

// Create the correct type of input control
else
{
// Create the control dependent on type
// Switch on the DataType forced to upper characters
switch( (parameter.DataType).ToUpper( ) )
{
case INT:
// Create a text box control for integer input
TextBox txtBox = new TextBox( );
theControl = txtBox;
// Create a length validator for an int
RegularExpressionValidator theIntValidator = new

RegularExpressionValidator( );
theIntValidator.ControlToValidate = controlId;
theIntValidator.ErrorMessage = displayName + " must

contain integers only";
theIntValidator.Text = "*";
theIntValidator.ValidationExpression = INT_REG_EXP;
validators.Add( theIntValidator );
break;
case DECIMAL:
// Create a text box control for free input
TextBox decimalBox = new TextBox( );
theControl = decimalBox;
// Create a length validator for a decimal
RegularExpressionValidator theDecimalValidator = new

RegularExpressionValidator( );
theDecimalValidator.ControlToValidate = controlId;
theDecimalValidator.ErrorMessage = displayName + " must

contain numeric characters and a simgle point only";
theDecimalValidator.Text = "*";
theDecimalValidator.ValidationExpression =

DECIMAL_REG_EXP;
validators.Add( theDecimalValidator );
break;
case VARCHAR:
case NVARCHAR:
// Create a text box control for the input
TextBox varCharBox = new TextBox( );
theControl = varCharBox;
// Create a length validator for a varchar
RegularExpressionValidator theVarCharValidator = new

RegularExpressionValidator( );
theVarCharValidator.ControlToValidate = controlId;
theVarCharValidator.ErrorMessage = displayName + " must

contain less than " + parameter.DataLength + " alpha characters";
theVarCharValidator.Text = "*";
theVarCharValidator.ValidationExpression = VARCHAR_REG_EXP

+ parameter.DataLength+ "}";
validators.Add( theVarCharValidator );
break;
case BIT:
// Create the drop down list with true and false
DropDownList boolean = new DropDownList( );
ListItem liTrue = new ListItem( "True", "TRUE" );
ListItem liFalse = new ListItem( "False", "FALSE" );
boolean.Items.Add( liTrue );
boolean.Items.Add( liFalse );
theControl = boolean;
break;
case DATETIME:
// Create a text box control for the input
TextBox dateTimeBox = new TextBox( );
theControl = dateTimeBox;
// Create a length validator for a varchar
RegularExpressionValidator theDateTimeValidator = new

RegularExpressionValidator( );
theDateTimeValidator.ControlToValidate = controlId;
theDateTimeValidator.ErrorMessage = displayName + " must

contain a valid date in the format dd/mm/yy";
theDateTimeValidator.Text = "*";
theDateTimeValidator.ValidationExpression =

DATETIME_REG_EXP;
validators.Add( theDateTimeValidator );
break;
default:
// Unkown, throw exception
throw new Exception( "CRITERIA SELECTOR: Unknown Data Type

" + (string)parameter.DataType );
}
}

// Set the id to be that of the DataName
theControl.ID = controlId;

// Give all controls a fixed width for display purposes
theControl.Width = Unit.Pixel( 100 );

// set the text properties
theControl.Font.Size = FontUnit.Point( FONT_SIZE );

// If this is mandatory add a required field validator
if( parameter.Optional != true )
{
RequiredFieldValidator mandatoryValidator = new RequiredFieldValidator( );
mandatoryValidator.ControlToValidate = theControl.ID;
mandatoryValidator.ErrorMessage = displayName + " is a mandatory field";
mandatoryValidator.Text = "*";
validators.Add( mandatoryValidator );
}

// Create any specialist regular expression validators
if( parameter.RegExpression != "" )
{
// Create the regular expression validator
RegularExpressionValidator theValidator = new RegularExpressionValidator(

);
theValidator.ControlToValidate = theControl.ID;
theValidator.ErrorMessage = displayName + ": " +

(string)parameter.RegExpressionErrorMsg;
theValidator.Text = "*";
theValidator.ValidationExpression = (string)parameter.RegExpression;
validators.Add( theValidator );
}
}

this.paramControls.Add(parameter.DataName,theContr ol);

// Add the tool tip
theControl.ToolTip = parameter.Description;

// Need to add the control to the correct table
// So initialise our control to the optional table
Table theTable = tblOptionalParameters;

// Check if the parameter is visible
if( parameter.Visible == false )
{
theTable = tblNotVisible;
}
// If visible check if the parameter is mandatory
else if( parameter.Optional == false )
{
// If so assign it to the mandatory table
theTable = tblMandatoryParameters;
}

// Add the control, label and validator to the correct table
AddToTable( theTable, theControl, validators, displayName, parameter.DataName,

(parameter.DataType).ToUpper( ), index );
}

/// <summary>
/// Add a parameter to the table
/// </summary>
/// <param name="theTable">The table to add the control to</param>
/// <param name="theControl">The control to add</param>
/// <param name="theValidator">The validators</param>
/// <param name="label">The display name</param>
/// <param name="paramName">The stored proc parameter name</param>
/// <param name="type">The parameter type</param>
private void AddToTable( Table theTable, Control theControl, ArrayList validators, string label,

string paramName, string type, int index )
{
// Create the table cells and row
Table paramTable = new Table( );
TableCell paramNameCell = new TableCell( );
TableCell paramTypeCell = new TableCell( );
TableCell paramIndexCell = new TableCell( );
TableCell labelCell = new TableCell( );
TableCell controlCell = new TableCell( );
TableCell validatorCell = new TableCell( );
TableRow theTableRow = new TableRow( );

// Add the parameter name to the table and hide it
paramNameCell.Text = paramName;
paramNameCell.Visible = false;

// Add the parameter type to the table and hide it
paramTypeCell.Text = type;
paramTypeCell.Visible = false;

// Add the parameter index to the table and hide it
paramIndexCell.Text = index.ToString( );
paramIndexCell.Visible = false;

// Add the controls label
labelCell.Text = label;
labelCell.Width = Unit.Pixel( 100 );
labelCell.Font.Size = FontUnit.Point( FONT_SIZE );
labelCell.HorizontalAlign = HorizontalAlign.Right;

// Add the control
controlCell.Controls.Add( theControl );
controlCell.Width = Unit.Pixel( 100 );
controlCell.HorizontalAlign = HorizontalAlign.Left;

// Add the validator(s) if there are any
for( int i = 0; i< validators.Count; ++i )
{
validatorCell.Controls.Add( (Control)validators[ i ] );
}

// Give the validator cell a fixed width for display purposes
validatorCell.Width = Unit.Pixel( 20 );
validatorCell.Text = " ";
validatorCell.Visible = true;

// Add the cells to the row
theTableRow.Cells.Add( paramNameCell );
theTableRow.Cells.Add( paramTypeCell );
theTableRow.Cells.Add( paramIndexCell );
theTableRow.Cells.Add( labelCell );
theTableRow.Cells.Add( controlCell );
theTableRow.Cells.Add( validatorCell );

// Add the row to the table
paramTable.Rows.Add( theTableRow );

// Put this whole table in a single cell
TableCell tableCell = new TableCell( );
tableCell.Controls.Add( paramTable );

// Has the last row got the maximum number of cells
// Create new row if this is the title row or no rows
if( theTable.Rows.Count <= 1 || theTable.Rows[ theTable.Rows.Count -1 ].Cells.Count ==

MAX_CELLS )
{
// If so add a new row
TableRow newRow = new TableRow( );
newRow.Width = Unit.Percentage( 100 );
theTable.Rows.Add( newRow );

}

// Now add the parameter table cell
theTable.Rows[ theTable.Rows.Count -1 ].Cells.Add( tableCell );
}

Jul 21 '05 #1
0 1879

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

Similar topics

1
by: MonkeyBoy | last post by:
I am doing some some HTML manipulation in client-side script (IE5.x and IE6.x browsers only). Something like.. var tmpHTML = oTable.outerHTML // do something to the HTML her oTable.outerHTML =...
1
by: Tom Pearson | last post by:
I create controls and validators dynamically dependent on data at runtime. I create the control then the relevant validator(s) for it assigning the Control.ID as the control to validate. These...
6
by: Mark | last post by:
We have Validators embedded in an asp table server control. The table server control is necessary and cannot be replaced. We want to apply CSS formatting to the validators, but the validators...
3
by: John Blair | last post by:
Hi, I have validators outside of a datagrid (for adding a new grid row) - however when i click "edit" column and then the "update" column of a grid row that has been edited - my other...
1
by: epigram | last post by:
I'm trying to use the ASP.NET validators to check some client-side business rules. I've got two ASP TextBox controls (call them tbxYear1 and tbxYear2) used to enter a range of years. I've got a...
1
by: Gabriel Lozano-Morán | last post by:
When using the tabstrip control combined with a multipage (several pageview) there is a problem when using validators. The problem is that validation also occurs on the validators that are not on...
0
by: Tom Pearson | last post by:
I create controls and validators dynamically dependent on data at runtime. I create the control then the relevant validator(s) for it assigning the Control.ID as the control to validate. These...
2
by: Mike Surcouf | last post by:
Hi I have some regex validators on my page set to dynamic and like the way they appear after you tab out of a field and also when you try to postback the form. All OK so far When I register...
4
by: Madhur | last post by:
Hello All I am learning how to use ASP.NET Validators and would appreciate if someone could provide me with guidance. I have written very simple ASPX page below with a Dropdown list, a...
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...
0
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...
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)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.