Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding validation controls at run-time.

Status
Not open for further replies.

iaresean

Programmer
Mar 24, 2003
570
ZA
Hey All;

I have this little app that allows users to create games and then creates rules regarding the scores of the games.

The rules that they can create allow them to specify that the score should be >, < or != to a specified integer value.

Using these rules I would like to dynamically create and populate 'their' pages with asp.net 2 validator controls based on their rules. I thought it would be easy enough, but I can't seem to find a simple enough validator control that will allow me to specify these basic rules (ie. score != 15, or score > 0).

Does anyone know of a way I could go about doing this? I suppose creating custom controls may be the best, but I will be sacrificing the client side message box validation that I require. :-(

Thank you for any and all help!

Sean. [peace]
 
Doh.....stupid.

Anyway, for those interested here is how I did it:

Code:
CompareValidator oVal;

DataSet dsRules = GameScrRule.SelectGameRules(oGame._iId);

for (int i = 0; i < dsRules.Tables[0].Rows.Count; i++)
{
    DataRow drRow = dsRules.Tables[0].Rows[i];

    oVal = new CompareValidator();

    // Now create the compare validator control
    oVal.ID = "cvalRule" + i.ToString();

    oVal.Display = ValidatorDisplay.None;

    if (drRow["sr_Sign"].ToString() == ">")
        oVal.Operator = ValidationCompareOperator.GreaterThan;
    else if (drRow["sr_Sign"].ToString() == "<")
        oVal.Operator = ValidationCompareOperator.LessThan;
    else if (drRow["sr_Sign"].ToString() == "!=")
        oVal.Operator = ValidationCompareOperator.NotEqual;

    oVal.ControlToValidate = "txtScore";
    oVal.Type = ValidationDataType.Integer;
    oVal.ValueToCompare = drRow["sr_Value"].ToString();

    oVal.ErrorMessage = drRow["sr_Message"].ToString();
    
    divValidationControls.Controls.Add(oVal);
}

Regards

Sean. [peace]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top