Page view counter

best practices for developing ASP.Net controls with client scripting

Last post 10-13-2006 2:26 AM by Haissam. 4 replies.

Sort Posts:

  • best practices for developing ASP.Net controls with client scripting

    10-04-2006, 3:27 PM
    • Loading...
    • markvw
    • Joined on 10-04-2006, 7:24 PM
    • Posts 1
    • Points 5

    Hello. I was wondering if when developing custom controls in asp.net that need client script if it is better to emit the script inline with the code or to use a script file that the page can refer to. Any ideas would be much appreciated.

     Thanks.

  • Re: best practices for developing ASP.Net controls with client scripting

    10-04-2006, 4:31 PM
    • Loading...
    • Javier Luna
    • Joined on 08-29-2006, 4:34 PM
    • Lima, Peru
    • Posts 592
    • Points 2,426

    Hi mark,

    I use your second option. A script file that the page can refer it.

    Good Coding!

    Javier Luna
    http://guydotnetxmlwebservices.blogspot.com/

     

    from Villa El Salvador for world!
  • Re: best practices for developing ASP.Net controls with client scripting

    10-04-2006, 5:16 PM
    • Loading...
    • PeterBrunone
    • Joined on 06-19-2002, 9:15 AM
    • I'm standing behind you.
    • Posts 3,681
    • Points 18,331
    • TrustedFriends-MVPs

    It depends on how dynamic the script needs to be.  For example, with EasyListBox, I do both; the bulk of the JS is in an external file, but functionality that changes with the page content is rendered inline with the web form.

    Cheers, 

    Peter Brunone
    MS MVP, ASP.NET
    Founder, EasyListBox.com
    Do the impossible, and go home early.
  • Re: best practices for developing ASP.Net controls with client scripting

    10-04-2006, 6:10 PM
    • Loading...
    • flanakin
    • Joined on 10-05-2003, 7:06 PM
    • Washington, DC area
    • Posts 384
    • Points 1,901

    Personally, I see three options. In preferencial order, they are (a) a separate JS file; (b) a cache-enabled ASPX file; and, (c) inline scripting. Use a JS file in any case where your script is static. The reason behind this is that modern web browsers will cache these files and ensure your app performs as best as possible -- remember that JavaScript is parsed when executed, so every little bit helps. If you require dynamic content, try putting the script in a separate ASPX page that utilizes cache headers to maximize the cacheability. In the event that you have code that is dependant upon server controls, use inline scripting. Even if you do go this route, tho, I'd suggest calling functions that are specified in cache-controlled locations to minimize page size and maximize performance.

    On a side note, if you have no more than 5-10 lines of code, I wouldn't worry about it. Just stick it on the page since that's the simplest method. The real reasons to separate script into its own file is for performance and/or maintainability... well, and all the other *ilities, as well Smile

    Michael Flanakin | Microsoft Consulting Services
    www.michaelflanakin.com
  • Re: best practices for developing ASP.Net controls with client scripting

    10-13-2006, 2:26 AM
    • Loading...
    • Haissam
    • Joined on 10-05-2006, 2:25 AM
    • Beirut - Lebanon
    • Posts 5,632
    • Points 37,391

    Personally i use external files when i got a large number of javascript written in one webpage, in this way u can make reading and debugging ur code easier then putting them inline.

    Happy coding

    Haissam Abdul Malak
    MCAD.NET
    | Blog |
Page 1 of 1 (5 items)