[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 886
  • Last Modified:

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')"

0
DOT_NET
Asked:
DOT_NET
  • 7
  • 3
  • 2
  • +1
1 Solution
 
hismightinessCommented:
What variable are you trying to pass into it?  Where is it coming from?
0
 
DOT_NETAuthor Commented:
Actually i like to pass the ID of textbox as parameter

as the customvalidator functions uses same function most of the textbox

0
 
hismightinessCommented:
Sorry, another question, are you trying to re-use the server validation function?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
DOT_NETAuthor Commented:
yes i like to use same function for diff customvalidator controls
0
 
mmarinovCommented:
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
0
 
DOT_NETAuthor Commented:
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

0
 
DOT_NETAuthor Commented:
@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

0
 
mmarinovCommented:
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
0
 
DOT_NETAuthor Commented:
i guess i can find out the way
0
 
mmarinovCommented:
DOT_NET,

if you want to pass more that on values why you can use sessions
then you don't have to set a specific control to validate

or even better in the button_onclick ( for example ) you can perform your validation manually :)

B..M
0
 
DOT_NETAuthor Commented:
performing validation manually is last option i guess
0
 
DOT_NETAuthor Commented:
thanks mmarinov i will post my commnet after tring it out
0
 
boulder_bumCommented:
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

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now