[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

customvalidator question

Posted on 2004-09-24
14
Medium Priority
?
873 Views
Last Modified: 2008-02-07
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
Comment
Question by:DOT_NET
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 2
  • +1
14 Comments
 
LVL 9

Expert Comment

by:hismightiness
ID: 12146949
What variable are you trying to pass into it?  Where is it coming from?
0
 

Author Comment

by:DOT_NET
ID: 12147027
Actually i like to pass the ID of textbox as parameter

as the customvalidator functions uses same function most of the textbox

0
 
LVL 9

Expert Comment

by:hismightiness
ID: 12147275
Sorry, another question, are you trying to re-use the server validation function?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:DOT_NET
ID: 12147305
yes i like to use same function for diff customvalidator controls
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12147329
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
 

Author Comment

by:DOT_NET
ID: 12147404
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
 

Author Comment

by:DOT_NET
ID: 12147468
@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
 
LVL 28

Expert Comment

by:mmarinov
ID: 12147478
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
 

Author Comment

by:DOT_NET
ID: 12147494
i guess i can find out the way
0
 
LVL 28

Accepted Solution

by:
mmarinov earned 150 total points
ID: 12147503
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
 

Author Comment

by:DOT_NET
ID: 12147513
performing validation manually is last option i guess
0
 

Author Comment

by:DOT_NET
ID: 12147521
thanks mmarinov i will post my commnet after tring it out
0
 
LVL 8

Expert Comment

by:boulder_bum
ID: 12147799
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
 
LVL 8

Expert Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question