Groups | Blog | Home
all groups > asp.net webcontrols > october 2007 >

asp.net webcontrols : OnServerValidate handler - how to know which CustomValidator is using it ?



northof40
10/26/2007 12:01:45 AM
Hi - I have set up a number of CustomValidators all of which specify
the same method as on their 'OnServerValidate' property.

Within the method handling the custom validation how can I determine
which CustomValidator is calling ?

I would like to modify the error message dynamically but without
knowing whihc CustomValidator is firing I cannot.

Any ideas ?

Richard.
Nathan Sokalski
10/29/2007 4:47:02 PM
Try using the sender parameter
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

[quoted text, click to view]

northof40
10/31/2007 6:39:23 PM
[quoted text, click to view]
Thanks for your reply - I'm not quite sure what you mean though.

When I look at source.ToString() I get ...

"System.Web.UI.WebControls.CustomValidator"

.... which doesn't tell me which CustomValidator is causing the handler
to fire. Maybe I misunderstood what you meant - could you expand on
it ?

Thanks

Richard.



[quoted text, click to view]

Nathan Sokalski
11/1/2007 11:46:15 PM
Try casting source as a CustomValidator, and then getting the ID attribute,
like the following (the following is VB.NET code):

CType(source,System.Web.UI.WebControls.CustomValidator).ID

Because source is an Object, you must first convert it to the correct type.
Then use the ID property to determine which of the validators it is. If this
does not work, it may help if you could send us your code so that we can see
exactly what techniques you are using.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

[quoted text, click to view]

AddThis Social Bookmark Button