473,569 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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( FunctionParamet er parameter, int index )
{
// Get the display name
string displayName = parameter.Displ ayName;

// Get the control Id
string controlId = parameter.DataN ame;

// 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.Visi ble )
{
// Create a text box to store the default value in
TextBox defaultTextBox = new TextBox( );

// get the default value for this control
if(parameter.Va lue != 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)paramet er.PredefinedVa lues != "NotSet" )
{
// If we have a list of predefined values we need a list box
DropDownList dropDownList = new DropDownList( );
dropDownList.Da taSource = GetListItems( (string)paramet er.PredefinedVa lues

);
dropDownList.Da taTextField = "DisplayVal ue";
dropDownList.Da taValueField = "StoredProcValu e";
dropDownList.Da taBind( );
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.Data Type).ToUpper( ) )
{
case INT:
// Create a text box control for integer input
TextBox txtBox = new TextBox( );
theControl = txtBox;
// Create a length validator for an int
RegularExpressi onValidator theIntValidator = new

RegularExpressi onValidator( );
theIntValidator .ControlToValid ate = controlId;
theIntValidator .ErrorMessage = displayName + " must

contain integers only";
theIntValidator .Text = "*";
theIntValidator .ValidationExpr ession = 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
RegularExpressi onValidator theDecimalValid ator = new

RegularExpressi onValidator( );
theDecimalValid ator.ControlToV alidate = controlId;
theDecimalValid ator.ErrorMessa ge = displayName + " must

contain numeric characters and a simgle point only";
theDecimalValid ator.Text = "*";
theDecimalValid ator.Validation Expression =

DECIMAL_REG_EXP ;
validators.Add( theDecimalValid ator );
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
RegularExpressi onValidator theVarCharValid ator = new

RegularExpressi onValidator( );
theVarCharValid ator.ControlToV alidate = controlId;
theVarCharValid ator.ErrorMessa ge = displayName + " must

contain less than " + parameter.DataL ength + " alpha characters";
theVarCharValid ator.Text = "*";
theVarCharValid ator.Validation Expression = VARCHAR_REG_EXP

+ parameter.DataL ength+ "}";
validators.Add( theVarCharValid ator );
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.A dd( liTrue );
boolean.Items.A dd( 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
RegularExpressi onValidator theDateTimeVali dator = new

RegularExpressi onValidator( );
theDateTimeVali dator.ControlTo Validate = controlId;
theDateTimeVali dator.ErrorMess age = displayName + " must

contain a valid date in the format dd/mm/yy";
theDateTimeVali dator.Text = "*";
theDateTimeVali dator.Validatio nExpression =

DATETIME_REG_EX P;
validators.Add( theDateTimeVali dator );
break;
default:
// Unkown, throw exception
throw new Exception( "CRITERIA SELECTOR: Unknown Data Type

" + (string)paramet er.DataType );
}
}

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

// Give all controls a fixed width for display purposes
theControl.Widt h = 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.Optio nal != true )
{
RequiredFieldVa lidator mandatoryValida tor = new RequiredFieldVa lidator( );
mandatoryValida tor.ControlToVa lidate = theControl.ID;
mandatoryValida tor.ErrorMessag e = displayName + " is a mandatory field";
mandatoryValida tor.Text = "*";
validators.Add( mandatoryValida tor );
}

// Create any specialist regular expression validators
if( parameter.RegEx pression != "" )
{
// Create the regular expression validator
RegularExpressi onValidator theValidator = new RegularExpressi onValidator(

);
theValidator.Co ntrolToValidate = theControl.ID;
theValidator.Er rorMessage = displayName + ": " +

(string)paramet er.RegExpressio nErrorMsg;
theValidator.Te xt = "*";
theValidator.Va lidationExpress ion = (string)paramet er.RegExpressio n;
validators.Add( theValidator );
}
}

this.paramContr ols.Add(paramet er.DataName,the Control);

// Add the tool tip
theControl.Tool Tip = parameter.Descr iption;

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

// Check if the parameter is visible
if( parameter.Visib le == false )
{
theTable = tblNotVisible;
}
// If visible check if the parameter is mandatory
else if( parameter.Optio nal == false )
{
// If so assign it to the mandatory table
theTable = tblMandatoryPar ameters;
}

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

(parameter.Data Type).ToUpper( ), index );
}

/// <summary>
/// Add a parameter to the table
/// </summary>
/// <param name="theTable" >The table to add the control to</param>
/// <param name="theContro l">The control to add</param>
/// <param name="theValida tor">The validators</param>
/// <param name="label">Th e 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.T ext = paramName;
paramNameCell.V isible = false;

// Add the parameter type to the table and hide it
paramTypeCell.T ext = type;
paramTypeCell.V isible = 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.Horiz ontalAlign = HorizontalAlign .Right;

// Add the control
controlCell.Con trols.Add( theControl );
controlCell.Wid th = Unit.Pixel( 100 );
controlCell.Hor izontalAlign = HorizontalAlign .Left;

// Add the validator(s) if there are any
for( int i = 0; i< validators.Coun t; ++i )
{
validatorCell.C ontrols.Add( (Control)valida tors[ i ] );
}

// Give the validator cell a fixed width for display purposes
validatorCell.W idth = Unit.Pixel( 20 );
validatorCell.T ext = " ";
validatorCell.V isible = true;

// Add the cells to the row
theTableRow.Cel ls.Add( paramNameCell );
theTableRow.Cel ls.Add( paramTypeCell );
theTableRow.Cel ls.Add( paramIndexCell );
theTableRow.Cel ls.Add( labelCell );
theTableRow.Cel ls.Add( controlCell );
theTableRow.Cel ls.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.Contr ols.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.C ount <= 1 || theTable.Rows[ theTable.Rows.C ount -1 ].Cells.Count ==

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

}

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

Jul 21 '05 #1
0 1901

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

Similar topics

1
2112
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 = tmpHTML Before the changes, client-side .Net field validators (RegularExpressionValidator, RangeValidator, etc.) work fine... after the changes,...
1
2013
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 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...
6
1617
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 have a default RED font that appears to be difficult to remove. We could hard code in a blank font color into the .aspx html for each validator, but...
3
1863
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 validators on the page fire which i don't want - i've tried to make them invisible - this hides the controls but i get a strange error when i click the...
1
2111
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 couple things I need to check: 1) tbxYear1 and tbxYear2 are both optional, but if values are entered they have to integers and non-negative 2) if...
1
1656
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 the currently selected pageview of the multipage. To prevent this from happening I disable all the validators and only enable the validators on the...
0
255
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 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...
2
1725
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 for the client side event of a textbox using ... textBox.Attributes.Add("onKeyUp","javascriptfunction");
4
1261
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 button. If a value of 3 is selected inside dropdown list , I add two text boxes each attached with validators.
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.