Try to compile ASP. NET program with JScript. net

Source: Internet
Author: User
ArticleDirectory
    • I. Why do I have such an idea?
    • 2. What is JScript. Net?
    • Iii. Advantages of JScript. net over traditional JavaScript and JScript
    • 4. Example of JScript. Net accessing the database
    • 5. Notes
    • Vi. Related Resources
I. Why do I have such an idea?

I have been engaged in Web Front-end development, so I am familiar with CSS and JavaScript, and I am also familiar with background programming after work. Naturally, I also know C, I also know that C # is Microsoft. I am also improving the main language of the net platform. At the same time, I also wondered if I could use the Javascript I am most familiar with as the background.Programming LanguageHere, I am not referring to the traditional ASP, but ASP. NET. With this idea, I finally discovered that JScript. Net can meet my needs. I will take a note for the first time. Of course, I just used it for play, because I used JScript. net is clearly unknown as the development language of the actual project, because too few people are used, there are few documents, and it is not convenient for teams to develop large projects, the worst thing is that it does not have a good development and debugging IDE, and even Microsoft's own vs does not support it very well (here it refers to the operation. NET provides automatic completion and debugger functions, rather than basic JS writing. for basic programming, you can select apatana and vs2008 ).

2. What is JScript. Net?

I believe you will never be unfamiliar with JavaScript, because you are not unfamiliar with Ajax. In fact, JScript is a Microsoft version of JavaScript, which is almost the same as JavaScript and extends some practical methods. In the early days when ASP was popular, it was also the same as VBScript as a script language running on the server. And JScript. net can be said to be the latest version of JScript, namely JScript 8.0, which has a qualitative breakthrough in functionality. It is designed to provide access to JScript developers. net public class library, that is, it can be developed based on. NET platform applicationsProgram, Or even the. NET winform program. Through understanding the JScript 8.0 documentation, we can find that through.. Net SDK or vs ide compiles JS files into EXE or DLL files, which are based on. NET Common intermediate language compilation, so it can be accessed by other languages, which will certainly open your eyes.

Iii. Advantages of JScript. net over traditional JavaScript and JScript

Through understanding JScript. NET and comparing it with similar languages, we can easily find its advantages:

(1) more functions.Provides many additional practical methods and features.

(2) more object-oriented.You can directly provide keywords such as class and inheritance to explicitly declare the variable type, as well as the concept and definition of the package for convenience.CodeOrganization and management.

(3) execution can be faster.Like the. NET platform that supports other languages, it supports compilation and execution, and the execution efficiency is almost the same as that of other languages.

4. Example of JScript. Net accessing the database

The code is quite simple, so no comments are added. You can see the common. Net method. I passed the test and changed the database connection and SQL statement to your own actual data query, requiring. NET 2.0 or above environments. This example is not original and copied online.

<% @ Page Language = " JScript "   %>
<% @ Import namespace = " System. Data. sqlclient "   %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< Html Xmlns = "Http://www.w3.org/1999/xhtml"   >
< Head Runat = "Server" >
< Title > Use JScript. net to compile ASP. NET program instances </ Title >
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< Script Runat = "Server" >
Function Page_load (sender, E: eventargs)
{
If ( ! Ispostback)
{
VaR DB: String =   " Server =.; uid = sa; Pwd = sa; database = News " ;
VaR SQL: String =   " Select top 10 * From News " ;
VaR RS = Sqldatareader;
VaR Conn: sqlconnection =   New Sqlconnection (db );
VaR CMD: sqlcommand =   New Sqlcommand (SQL, Conn );
Try  
{
Conn. open ();
RS = Cmd. executereader ();
If (Rs. hasrows)
{
While (Rs. Read ())
{
Response. Write (RS [ " Title " ]. Tostring () + " <Br/> " );
}
}
Else
{
Response. Write ( " Not found " );
}
Rs. Close ();
Conn. Close ();
}
Catch (E)
{
Response. Write ( " Error! " );
}
Finally  
{
Cmd. Dispose ();
Conn. Dispose ();
}
}
}
</ Script >
</ Form >
</ Body >
</ Html > 5. Notes

(1) In general, we use ASP. net web control page (aspx file) page header using the page command to specify the page using the default programming language, in the HTML body we can use the way to include the Execution code block. However, I found that using the page_load method or operating some asp. when using the. NET Server Control, you must use the <SCRIPT> block with the runat = "server" attribute. Otherwise, nothing is output. I don't know if it is my system problem, hope you can give me some advice.

(2) The official JScript documentation says that the declaration of variable types can be specified or not specified. For example, var SQL: string can be simply written as var SQL, however, I found that the types of some variables must be declared, otherwise there will be problems. For example, e in function page_load (sender, E: eventargs) must be explicitly declared as eventargs, otherwise, you will not get the expected results.

Vi. Related Resources

· Common JScript. Net tutorials

· Msdn contains a JScript. Net demo instance

· JScript 8.0 Language Reference Manual CHM download

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.