G
gary.smith
Hello,
I am building an table out of dynamic data for the purposes of editing
rows. The scope of the project didn't allow for an elegant way of
doing this with forms.
Basically I add a control a cell to a row to the table. That control
has a validation associated with it. The problem is on the next
postback I need to do a bunch of odd stuff to it so my first thought
was to use some type of client validation. In it's simplist form, I
basically want to validate that the field is of type currency. This is
simple enough in JS or in RegExp.
Here is a sample of the logic:
oCell = New System.Web.UI.WebControls.TableCell
oTextbox = New System.Web.UI.WebControls.TextBox
oTextbox.ID = "LastMaintenanceCost_" & sUniqueRowID
oTextbox.Text =
LastMaintenanceCost.ToString("$#,##0.00;($#,##0.00);$0.00")
oTextbox.Width =
System.Web.UI.WebControls.Unit.Point(50)
oCell.Controls.Add(oTextbox)
oRequiredValidator = New
System.Web.UI.WebControls.RequiredFieldValidator
oRequiredValidator.ID = "LastMaintenanceCostRequired_"
& sUniqueRowID
oRequiredValidator.ControlToValidate =
"LastMaintenanceCost_" & sUniqueRowID
oRequiredValidator.ErrorMessage = "<br>Required"
oRequiredValidator.Display = ValidatorDisplay.Dynamic
oRequiredValidator.EnableClientScript = True
oCell.Controls.Add(oRequiredValidator)
oRegExpValidator = New
System.Web.UI.WebControls.RegularExpressionValidator
oRegExpValidator.ID = "LastMaintenanceCostRegExp_" &
sUniqueRowID
oRegExpValidator.ControlToValidate =
"LastMaintenanceCost_" & sUniqueRowID
oRegExpValidator.ErrorMessage = "<br>Currency values
only"
oRegExpValidator.Display = ValidatorDisplay.Dynamic
oRegExpValidator.EnableClientScript = True
oRegExpValidator.ValidationExpression =
"^\$?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$"
oCell.Controls.Add(oRegExpValidator)
oRow.Cells.Add(oCell)
So my question is what do I need to do to make this logic execute on
the client side? I have enabled client scripting but that doesn't seem
to do anything.
Also, is the validation code IE specific or does it work on browsers
such as Mozilla or FireFox?
I am building an table out of dynamic data for the purposes of editing
rows. The scope of the project didn't allow for an elegant way of
doing this with forms.
Basically I add a control a cell to a row to the table. That control
has a validation associated with it. The problem is on the next
postback I need to do a bunch of odd stuff to it so my first thought
was to use some type of client validation. In it's simplist form, I
basically want to validate that the field is of type currency. This is
simple enough in JS or in RegExp.
Here is a sample of the logic:
oCell = New System.Web.UI.WebControls.TableCell
oTextbox = New System.Web.UI.WebControls.TextBox
oTextbox.ID = "LastMaintenanceCost_" & sUniqueRowID
oTextbox.Text =
LastMaintenanceCost.ToString("$#,##0.00;($#,##0.00);$0.00")
oTextbox.Width =
System.Web.UI.WebControls.Unit.Point(50)
oCell.Controls.Add(oTextbox)
oRequiredValidator = New
System.Web.UI.WebControls.RequiredFieldValidator
oRequiredValidator.ID = "LastMaintenanceCostRequired_"
& sUniqueRowID
oRequiredValidator.ControlToValidate =
"LastMaintenanceCost_" & sUniqueRowID
oRequiredValidator.ErrorMessage = "<br>Required"
oRequiredValidator.Display = ValidatorDisplay.Dynamic
oRequiredValidator.EnableClientScript = True
oCell.Controls.Add(oRequiredValidator)
oRegExpValidator = New
System.Web.UI.WebControls.RegularExpressionValidator
oRegExpValidator.ID = "LastMaintenanceCostRegExp_" &
sUniqueRowID
oRegExpValidator.ControlToValidate =
"LastMaintenanceCost_" & sUniqueRowID
oRegExpValidator.ErrorMessage = "<br>Currency values
only"
oRegExpValidator.Display = ValidatorDisplay.Dynamic
oRegExpValidator.EnableClientScript = True
oRegExpValidator.ValidationExpression =
"^\$?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$"
oCell.Controls.Add(oRegExpValidator)
oRow.Cells.Add(oCell)
So my question is what do I need to do to make this logic execute on
the client side? I have enabled client scripting but that doesn't seem
to do anything.
Also, is the validation code IE specific or does it work on browsers
such as Mozilla or FireFox?