Click to See Complete Forum and Search --> : How to use JavaScript function in user control in ASP.net


rajesh20k
October 1st, 2005, 07:29 AM
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.

columbus2003
October 5th, 2005, 10:28 PM
If you have no other way, just write the whole client-side script by using Response.Write() function.

Alsvha
October 6th, 2005, 02:22 AM
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?