Link to home
Start Free TrialLog in
Avatar of DOT_NET
DOT_NET

asked on

customvalidator question

please help me
i want to pass parameters in customvalidator function

this is my code

<asp:CustomValidator id="Title" runat="server" EnableClientScript="False" ErrorMessage="Error in title"
 OnServerValidate="checkValid"></asp:CustomValidator>
                                                                        


Sub checkValid(ByVal s As Object, ByVal e As ServerValidateEventArgs)

end sub

this works fine but

 i like to pass somthing like this

 OnServerValidate="checkValid('title')"

Avatar of hismightiness
hismightiness

What variable are you trying to pass into it?  Where is it coming from?
Avatar of DOT_NET

ASKER

Actually i like to pass the ID of textbox as parameter

as the customvalidator functions uses same function most of the textbox

Sorry, another question, are you trying to re-use the server validation function?
Avatar of DOT_NET

ASKER

yes i like to use same function for diff customvalidator controls
Hi hismightiness,

CType(source, CustomValidator).ControlToValidate will return ( in string ) the id of the control you want to validate
if you want to search for this control , just type

Page.FindControl (  CType(source, CustomValidator).ControlToValidate )

B..M
Avatar of DOT_NET

ASKER

My quesyion is what parameters to be passed for the function checkValid


Sub checkValid(ByVal s As Object, ByVal e As ServerValidateEventArgs)

end sub

Default checkValid() function  passes the parameters for  Object and ServerValidateEventArgs



if i add new new parameter like

Sub checkValid(ByVal s As Object, ByVal e As ServerValidateEventArgs,Byval controlID as string)

end sub

then

OnServerValidate="checkValid('title')" doest work

Avatar of DOT_NET

ASKER

@mmarinov ur comment might help but
apart from control ID to validate i have to pass the maximum length for that textbox as parameter.
 which can't be retrieved in function without passing as parameter

DOT_NET,

sorry, but i did not read your question carefully
you can not set a parameter in the way you want, BUT
as i understand your question correclty - you want to use one custom validator to validate more than one controls - correct ?
if yes you have to use

customValidator1.ControlToValidate = "textbox1" and the textbox1 should be put in some conditions
the same conditions that will determine which id you want to pass like in the way you wanted
B..M
Avatar of DOT_NET

ASKER

i guess i can find out the way
ASKER CERTIFIED SOLUTION
Avatar of mmarinov
mmarinov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DOT_NET

ASKER

performing validation manually is last option i guess
Avatar of DOT_NET

ASKER

thanks mmarinov i will post my commnet after tring it out
If you want to use the same server-side function, you'd simply assign the same ServerValidateEventHandler. You DO NOT need a custom implementation for this:

   C#
this.CustomValidator1.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(this.checkValid);
this.CustomValidator2.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(this.checkValid);

   VB.NET
AddHandler CustomValidator1.ServerValidate, checkValid
AddHandler CustomValidator2.ServerValidate, checkValid

PS- You'll want to assign the server-side event handlers in the OnInit event handler of the page.