tailieunhanh - Wrox Professional Web Parts and Custom Controls with ASP.NET 2.0 phần 7
Tất cả ngôn ngữ .NET đều được dịch sang dạng ngôn ngữ trung gian của Microsoft (MSIL – Microsoft Intermediate Language) trước rồi mới được dịch sang dạng mã thực thi bởi một trình dịch JIT (Just – in Time) trên nền .NET. CLR và MSIL cho phép tất cả các ngôn ngữ .NET làm việc với nhau. | Adding Advanced Functionality Dynamically Generating Code The next step up the evolutionary ladder of client-side code writing is to dynamically generate your code and insert it into your page. The first step in generating dynamic client-side code is to prepare in your server-side code the client-side code to be added to the page and concatenate it into a string variable. The range of code that you can build is infinite but I ll stick to the simple SayHello example. This Visual Basic 2005 example puts the SayHello program into a single string Dim strSayHello As String strSayHello script function SayHello _ Hello World script In C string strSayHello strSayHello script function SayHello Hello World script Even if your code is being generated dynamically it s often a good idea to write an initial static version of the code in the Source view of your page. This gives you all the IntelliSense support of the Visual Studio 2005 editor plus some syntax checking. It s also a good idea to do some testing with your static code before cutting the code out of your page and incorporating it into your server-side code. The next step is to add this routine to your page from your server-side code. The simplest way to do this is to use the Response object s Write method as this Visual Basic 2005 version does strSayHello In C strSayHello However there are two problems with this method. The first problem is that you have very little control over where the client-side code is added. Used from the Page_Load event of a WebForm for instance the script block is inserted ahead of the HTML and DOCTYPE tags that begin your Web page the code still executes in Internet Explorer however . Typically there are two places where you want to put your script At the head of the form so that the code is guaranteed to have been processed by the browser by the time the user works with the control that the code is associated with At
đang nạp các trang xem trước