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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

editable grid and validation problem

Status
Not open for further replies.

mariacri11

Programmer
Apr 9, 2003
22
0
0
CY
Hello!

Here is my problem:
I have an editable datagrid with edititem templates.
I want to validate the data entered into the grid using a RegularExpressionValidator, but I get this error:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:

Line 23: valid.Validate

The code I am using is:

Dim valid as RegularExpressionValidator=new System.Web.UI.WebControls.RegularExpressionValidator
valid.ErrorMessage="eroarrrrrrrrrrrrrrrre!!!!!!!!!!"
valid.ValidationExpression="\d{3}"
valid.ControlToValidate="test"
valid.Validate
 
Do you have an instance of the validator declared in your .aspx? A common cause of this erorr is trying to use a control which is not declared in the .aspx or is declared in the .aspx but does not have the attribute runat="server"

From your code it lookis like your trying to programatically create a validator and use it. I'm not sure if you can do this or not, I havent tried. You could of course just use the regular expression classes ti achieve this programatically without using a validator at all. Else if you want it to validate page input and display a suitable message then I'd reccomend adding the validator control to the .aspx and declaring it in the normal way fro controls.

hope this helps

Rob

 
Thanks Rob!

After trying to do this for a while I rconsidered using the effective control placed in the edititem template of my grid.
And it worked.
And it's easier.

Cri
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top