CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004
    Location
    India
    Posts
    55

    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.

  2. #2
    Join Date
    Dec 2002
    Location
    Myanmar
    Posts
    84

    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_

  3. #3
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: How to use JavaScript function in user control in ASP.net

    Quote 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
  •  





Click Here to Expand Forum to Full Width

Featured