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="checkVal id"></asp: CustomVali dator>
Sub checkValid(ByVal s As Object, ByVal e As ServerValidateEventArgs)
end sub
this works fine but
i like to pass somthing like this
OnServerValidate="checkVal id('title' )"
i want to pass parameters in customvalidator function
this is my code
<asp:CustomValidator id="Title" runat="server" EnableClientScript="False"
OnServerValidate="checkVal
Sub checkValid(ByVal s As Object, ByVal e As ServerValidateEventArgs)
end sub
this works fine but
i like to pass somthing like this
OnServerValidate="checkVal
What variable are you trying to pass into it? Where is it coming from?
ASKER
Actually i like to pass the ID of textbox as parameter
as the customvalidator functions uses same function most of the textbox
as the customvalidator functions uses same function most of the textbox
Sorry, another question, are you trying to re-use the server validation function?
ASKER
yes i like to use same function for diff customvalidator controls
Hi hismightiness,
CType(source, CustomValidator).ControlTo Validate 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).ControlTo Validate )
B..M
CType(source, CustomValidator).ControlTo
if you want to search for this control , just type
Page.FindControl ( CType(source, CustomValidator).ControlTo
B..M
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,By val controlID as string)
end sub
then
OnServerValidate="checkVal id('title' )" doest work
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,By
end sub
then
OnServerValidate="checkVal
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
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.ControlTo Validate = "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
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.ControlTo
the same conditions that will determine which id you want to pass like in the way you wanted
B..M
ASKER
i guess i can find out the way
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
performing validation manually is last option i guess
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.Serv erValidate += new System.Web.UI.WebControls. ServerVali dateEventH andler(thi s.checkVal id);
this.CustomValidator2.Serv erValidate += new System.Web.UI.WebControls. ServerVali dateEventH andler(thi s.checkVal id);
VB.NET
AddHandler CustomValidator1.ServerVal idate, checkValid
AddHandler CustomValidator2.ServerVal idate, checkValid
C#
this.CustomValidator1.Serv
this.CustomValidator2.Serv
VB.NET
AddHandler CustomValidator1.ServerVal
AddHandler CustomValidator2.ServerVal
PS- You'll want to assign the server-side event handlers in the OnInit event handler of the page.