Asp.Net Javascript-Ajax Coding Style Approach
-
Hi folks! I am new here and i search for my question and find nothing here..:rose: 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. :omg: 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)?:confused:
-
Hi folks! I am new here and i search for my question and find nothing here..:rose: 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. :omg: 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)?:confused:
xenonysf wrote:
o 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)?
There is no rules available on this. I always prefer to write them in a js file. Because it seperates javascript block from the ASPX, and I felt it's easy too.
-
xenonysf wrote:
o 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)?
There is no rules available on this. I always prefer to write them in a js file. Because it seperates javascript block from the ASPX, and I felt it's easy too.
-
Don't you ever need creating dynamic js code? I think there must be an approach to put script blocks to places that are most suitable. I am just looking for an advice :)
xenonysf wrote:
Don't you ever need creating dynamic js code?
What do you mean by dynamic JS code ?
xenonysf wrote:
I think there must be an approach to put script blocks to places that are most suitable
This depends on the programmer. Putting javascript in js file or putting it in ASPX page won't make any performance difference. I used to do this depends on the requirement. If the page contains big javascript block, I prefer to keep them in external JS file. If it is in a custom server control I prefer to use web resources concept by embedding the javascript files. Hope this helps
-
xenonysf wrote:
Don't you ever need creating dynamic js code?
What do you mean by dynamic JS code ?
xenonysf wrote:
I think there must be an approach to put script blocks to places that are most suitable
This depends on the programmer. Putting javascript in js file or putting it in ASPX page won't make any performance difference. I used to do this depends on the requirement. If the page contains big javascript block, I prefer to keep them in external JS file. If it is in a custom server control I prefer to use web resources concept by embedding the javascript files. Hope this helps
-
I mean creating a js code by code-behind. like string script = "jscodecode" + var +"codeceode"; ... ok I got what you mean i think. Thanks
xenonysf wrote:
I mean creating a js code by code-behind.
This is not a good method until you rally need it. It will be tough to maintain. If you are doing this to get some values from server, you can directly use them in javascript by putting it into a server executable block.