.js files

Discussion in 'ASP .Net' started by Mantorok, Sep 2, 2005.

  1. Mantorok

    Mantorok Guest

    Hi all

    I want to seperate my client-side validation into a seperate js file,
    unfortunately the .js functions have no concept of document.getElementById,
    is it possible to have external javascript files referencing page controls?

    Thanks
    Kev
    Mantorok, Sep 2, 2005
    #1
    1. Advertising

  2. Hi Kev,

    Yes you can define a separate javascript validation file for your
    application. By default every .net web application, access the validaiton
    file resided in the asp_net_client directory of your wwwroot. But if you want
    to write your own js file , you can do that, once you define, all your
    validation methods call will forward to that file.

    What you have to do is to define a property in the web config file.

    <system.web>
    <webControls clientScriptsLocation="/script_files/"/>
    </system.web>

    And now place the WebUIValidation.js in the script_files folder,


    --
    Wajahat Abbas

    http://www.wajahatabbas.com
    http://www.dotnetpakistan.com




    "Mantorok" wrote:

    > Hi all
    >
    > I want to seperate my client-side validation into a seperate js file,
    > unfortunately the .js functions have no concept of document.getElementById,
    > is it possible to have external javascript files referencing page controls?
    >
    > Thanks
    > Kev
    >
    >
    >
    =?Utf-8?B?V2FqYWhhdCBBYmJhcw==?=, Sep 2, 2005
    #2
    1. Advertising

  3. Mantorok

    Karl Seguin Guest

    I don't understand the initial question, but I'm not sure Wajahat answered
    it...

    in a .js file, you can do document.getElementById("blah"); just fine...the
    script is included in the page and works against that DOM

    Perhaps what you are asking is how to get access to ASP.Net ClientIds ?
    maybe you have stuff like
    document.getElementById('<%=MyControl.ClientID%>'); ??

    in this case, no, your .js file doesn't have access to this. The one
    solution is in your page create a bunch of js variables:

    <script language=JavaScript">
    //at bottom of page, or OnLoad event
    var username = document.getElementById("<%=UserName.ClientId%>");
    ....
    </script>

    and then in your js file, you have access to the "username" javascript
    variable...

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)


    "Wajahat Abbas" <> wrote in message
    news:...
    > Hi Kev,
    >
    > Yes you can define a separate javascript validation file for your
    > application. By default every .net web application, access the validaiton
    > file resided in the asp_net_client directory of your wwwroot. But if you
    > want
    > to write your own js file , you can do that, once you define, all your
    > validation methods call will forward to that file.
    >
    > What you have to do is to define a property in the web config file.
    >
    > <system.web>
    > <webControls clientScriptsLocation="/script_files/"/>
    > </system.web>
    >
    > And now place the WebUIValidation.js in the script_files folder,
    >
    >
    > --
    > Wajahat Abbas
    >
    > http://www.wajahatabbas.com
    > http://www.dotnetpakistan.com
    >
    >
    >
    >
    > "Mantorok" wrote:
    >
    >> Hi all
    >>
    >> I want to seperate my client-side validation into a seperate js file,
    >> unfortunately the .js functions have no concept of
    >> document.getElementById,
    >> is it possible to have external javascript files referencing page
    >> controls?
    >>
    >> Thanks
    >> Kev
    >>
    >>
    >>
    Karl Seguin, Sep 2, 2005
    #3
  4. Mantorok

    bond_003

    Joined:
    Jul 17, 2009
    Messages:
    1
    i tried creating javascript variables and keeping script in separate file. but i get 'list' not defined...thats the name of the variable i defined in the ascx page.
    i implement the separate javascript file because i am using 2 instances of the same user control..and it seems that the javascript is working on that last user control that is added.

    please let me know if there is a solution to having 2 instances of user control and working with javascript. i have used the 'clientid' to get unique id..but javascript is working with the last added user control
    bond_003, Sep 7, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom Hansen
    Replies:
    2
    Views:
    2,380
    Tom Hansen
    Nov 21, 2003
  2. Chad

    .vb files to .resx files

    Chad, Dec 17, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    297
  3. crazyprakash
    Replies:
    4
    Views:
    3,362
    adrian
    Oct 30, 2005
  4. Replies:
    4
    Views:
    936
    M.E.Farmer
    Feb 13, 2005
  5. Replies:
    3
    Views:
    1,431
    Rolf Magnus
    Jan 18, 2009
Loading...

Share This Page