Home All Groups Group Topic Archive Search About
Author
10 May 2005 5:18 AM
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?

Author
10 May 2005 2:32 PM
Brock Allen
The server side validation controls always run server side and are supported
client side in IE only, unfortunately.

-Brock
DevelopMentor
http://staff.develop.com/ballen



Show quoteHide quote
> 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?
>
Author
29 Jun 2005 5:09 PM
Elazar
Hello,
Try looking into the RegisterClientScriptBlock method
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuipageclassregisterclientscriptblocktopic.asp)
and the RegisterOnSubmitStatement
method(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuipageclassregisterclientscriptblocktopic.asp)

Hope this helps!

--
Elazar


Show quoteHide quote
"Brock Allen" wrote:

> The server side validation controls always run server side and are supported
> client side in IE only, unfortunately.
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>
> > 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?
> >
>
>
>
>