|
-
October 1st, 2005, 07:29 AM
#1
How to use JavaScript function in user control in ASP.net
Hi all,
We are developing client/server application in ASP.net with VB.net. We would like to use validation control using JavaScript. DotNet provides validation control but this is not fulfilling our requirement. We like to make a different type of function to validate email, website, numeric, alphanumeric and date type. But, my question is how to use this function in user control not webpage.
Let me explain with an example.
Suppose, a project contains one webpage and one usercontrol. User control (.ascx) is placed on webpage (.aspx). Three - text box and one button (This is web control not html control) are placed on user control (.ascx). Suppose, we press the button then textboxes should be validated. But page should not be post back until all textbox is not validated.
Any help is appreciated.
-
October 5th, 2005, 10:28 PM
#2
Re: How to use JavaScript function in user control in ASP.net
If you have no other way, just write the whole client-side script by using Response.Write() function.
 Let's go together 
_  columbus2003  _
-
October 6th, 2005, 02:22 AM
#3
Re: How to use JavaScript function in user control in ASP.net
 Originally Posted by rajesh20k
Hi all,
We are developing client/server application in ASP.net with VB.net. We would like to use validation control using JavaScript. DotNet provides validation control but this is not fulfilling our requirement. We like to make a different type of function to validate email, website, numeric, alphanumeric and date type. But, my question is how to use this function in user control not webpage.
Let me explain with an example.
Suppose, a project contains one webpage and one usercontrol. User control (.ascx) is placed on webpage (.aspx). Three - text box and one button (This is web control not html control) are placed on user control (.ascx). Suppose, we press the button then textboxes should be validated. But page should not be post back until all textbox is not validated.
Any help is appreciated.
Add an onClick to your button which returns a JavaScript function.
For instance, something along this line (if added from CodeBehind):
button.Attributes.Add("onClick", "return YourValidateFunction()")
Then in your JavaScript function return true or false depending on the result. Then you shouldn't experience a postback if false.
Alertnative, you could also place validations on "onBlur" on the fields by calling the scripts from that event.
Besides - why wouldn't dotNets regularexpression validator do the trick for you?
Last edited by Alsvha; October 6th, 2005 at 02:26 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|