|
-
Jul 16th, 2005, 06:29 AM
#1
Thread Starter
Junior Member
how to perform validation on textbox in templatecolumn of datagrid?
In my DataGrid i've created a textbox in one of the template column which means all rows of that template column will have the same ID for the textbox.
How do I perform validation on each textbox only when that row is selected using the Select event only
Thx!
Last edited by asp.net_vb.net; Jul 16th, 2005 at 06:33 AM.
-
Jul 16th, 2005, 08:05 AM
#2
Re: how to perform validation on textbox in templatecolumn of datagrid?
Place a validator in the templatecolumn too.
In the ItemDataBound event, do a FindControl() for the textbox and the validator, and set the validator's ControlToValidate property to the textbox... assign the textbox's ClientId property to the ControlToValidate property.
-
Jul 20th, 2005, 06:55 AM
#3
Thread Starter
Junior Member
Re: how to perform validation on textbox in templatecolumn of datagrid?
 Originally Posted by mendhak
Place a validator in the templatecolumn too.
In the ItemDataBound event, do a FindControl() for the textbox and the validator, and set the validator's ControlToValidate property to the textbox... assign the textbox's ClientId property to the ControlToValidate property.
VB Code:
Dim validator As System.Web.UI.WebControls.RegularExpressionValidator
validator = CType(e.Item.FindControl("Regularexpressionvalidator123"), System.Web.UI.WebControls.RegularExpressionValidator)
Dim txtbox As System.Web.UI.WebControls.TextBox
txtbox = CType(e.Item.FindControl("textbox"), System.Web.UI.WebControls.TextBox)
validator.ControlToValidate = txtbox.ClientID
this is what I typed in the itemdatabound event but there is an error saying
VB Code:
Line 612: txtbox = CType(e.Item.FindControl("textbox"), System.Web.UI.WebControls.TextBox)
Line 613:
Line 614: validator.ControlToValidate = txtbox.ClientID
-
Jul 20th, 2005, 07:11 AM
#4
Thread Starter
Junior Member
Re: how to perform validation on textbox in templatecolumn of datagrid?
 Originally Posted by mendhak
Place a validator in the templatecolumn too.
In the ItemDataBound event, do a FindControl() for the textbox and the validator, and set the validator's ControlToValidate property to the textbox... assign the textbox's ClientId property to the ControlToValidate property.
the purpose is to validate the textbox for that row only when a select button is clicked but not other textboxes located in the same column. But the problem is that they have the same ID for the txtbox and when the Controltovalidate is set to the textbox ID, it will validate all of the textbox controls which it should not
-
Jul 20th, 2005, 07:52 AM
#5
Re: how to perform validation on textbox in templatecolumn of datagrid?
OK, a few changes to what I said.
Instead of
validator.ControlToValidate = txtbox.ClientID
put
validator.ControlToValidate = txtbox
That should do it.
Btw, you never said what the error was, but try what I just said right now.
-
Jul 20th, 2005, 09:00 AM
#6
I wonder how many charact
Re: how to perform validation on textbox in templatecolumn of datagrid?
That won't work - the ControlToValidate property expects a string, not a control class object.
You never stated what the error was, but you need the UniqueID property.
validator.ControlToValidate = txtbox.UniqueID.
-
Jul 20th, 2005, 09:28 AM
#7
Thread Starter
Junior Member
Re: how to perform validation on textbox in templatecolumn of datagrid?
The error is
Code:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 613: txtbox = CType(e.Item.FindControl("textbox"), System.Web.UI.WebControls.TextBox)
Line 614:
Line 615: validator.ControlToValidate = txtbox.UniqueID
-
Jul 20th, 2005, 10:39 AM
#8
Re: how to perform validation on textbox in templatecolumn of datagrid?
 Originally Posted by nemaroller
That won't work - the ControlToValidate property expects a string, not a control class object.
You never stated what the error was, but you need the UniqueID property.
validator.ControlToValidate = txtbox.UniqueID.
My bad, but not-so-bad, I had no IDE and Intellisense
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|