Coffeehouse Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

a general asp.net question: Asp.Net Javascript-Ajax Coding Style Approach

Back to Forum: Coffeehouse
  • User profile image
    xenonysf

    Hi folks! I know this is not a asp.net forum but wanted to share it...

    Now i am developing a web application which has to many custom javascript blocks and it includes ms-ajax.
    Sometimes js codes are written into an external .js file, sometimes they are written into aspx file, some times they are registered from code-behind. Think about how it is getting messy. This might also lead to script conflicts as you might guess.

    So what i want to learn is; is there a BEST way for this coding style (arranging js scripts in an very effective way in terms of programmer view and application convenience)?

  • User profile image
    Human​Compiler

    This question (and your future coding questions) is better off posted in Techoff.

    To answer your question though, the flexibility is there because it doesn't always make sense to do it one way.  That said, I would be as consistent as possible in how you arrange and send your scripts down to the client.  For us, we do all of them as embedded resources and let ASP.NET AJAX send them down for us (usually by implementing IScriptControl and returning the appropriate script in GetScriptReferences), but even then it doesn't always make sense (like for global scripts that apply to the entire application).  As always, just be as consistent and organized as possible so you don't shoot yourself in the foot.  Smiley

  • User profile image
    xenonysf

    Thanks for answer. Admins can move my post to techoff if possible. i ll keep in mind Smiley

    Ok. I think you mean this. Great for me!
    http://www.asp.net/ajax/documentation/live/tutorials/IScriptControlTutorial1.aspx

    I have problems with determing a style for this type of arrangement. For example i have global function that runs when the ajax library is loaded. So i want to init some var.s in that function for controls. But if i write them statically into that function they are useless when the control is not in page(think a multiview contents). Should i write every potential required script block as global to somewhere for controls then?



  • User profile image
    Human​Compiler

    Go through that tutorial.  It will help you with what you need to know.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.