|
|||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
BackgroundI needed to make a portion of Web Page to refresh without refreshing the entire page. Everytime I tried, it would always refresh the entire page. I got very frustrated, then I read an article from CodeProject (CodeProject Discussion Boards) and thought I would talk to Uwe Kein (the Author) about this. His suggestion was to use Remote Scripting which by the articles I read was the way to go. Unfortunately, my company didn't have that installed on their dev or production systems. I couldn't wait for them, so I tried scriptlets. After a lot of trial and error, I got it to work. I am writing this article to try and help anyone else in this situation. What will this do for you?Show you how to refresh a scriptlet every second using a timer inside the scriptlet. This example uses a DNS-Connection-less (meaning you don't have to create a System DNS entry through ODBC) way to access the MS-Access database, but you can adapt it to any other by changing the ConnectionString (see below formats): //Build the connection string // //ConnectionStringFormat(seebelow): //ConnectionString="DRIVER=SQLServer;SERVER=MySQLServer;CATALOG=MyDatabase;UID=USERID;PWD=Password"; // //forSQL7.0: //ConnectionString="DRIVER=SQLServer;SERVER=TopTen;CATALOG=TopTen;UID=TopTen;PWD=TopTen"; // //for Access Database (on Server): //ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;" &_ // "Data Source=\\\\SERVER\\Share\\directory\\TopTen.mdb"; // //for Access Database (on local drive): //ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;" &_ // "Data Source=C:\\Database\\TopTen.mdb"; I have included an Access2000 Database called/Located at C:\TopTen\TopTen.mdb to use for the example, or you can use the text file TopTen.txt which will create a Table, User Login, User Role, Primary Key, and Insert ten rows for an SQL 7.x database.
Note: if you want to use ASP (server calls) code, write it as a "JavaScript" function and use
What are scriptletsScriptlets are HTML pages that heavily exploit the DHTML object model. Here is how simple it is...write a normal HTML file. Create an function for the scriptlet called "CreatePage". Now, create a "new" object called public_description and assign it the result of the function. This function works as a the constructor of the scriptlet object. In one sense, the public_description variable is like a header file for a C++ class. It defines all the properties and methods that the scriptlet exposes. See the example below: // declare the object interface (constructor) public_description = new CreatePage(); var InScriptlet = (typeof(window.external.version) == "string"); // set some variables mEnabled = 1; mTimer = 0 function CreatePage() { this.Refresh = Refresh; this.Enable = Enable; }
Since a scriptlet is an HTML or ASP page (and can also be displayed as a stand-alone document), you
might occasionally incur a system error due to a property or a method that IE 4 (or higher) doesn't
find. This only happens if your scriptlet attempts to access its parent environment. To work around
this you need a way to detect whether a given page is viewed as a scriptlet or not. Since the
var InScriptlet = (typeof(window.external.version) == "string");
The variable above The way to get it to refresh is either by calling the "Refresh" method or by setting a timer
in the mTimer = window.setInterval( "DoUpdatePage()", 1000, "VBScript" )
Since both ActiveX controls and scriptlets are inserted through the same tag ActiveX Control: <OBJECT> id="Button1" classid="..." width="..." height="..." <param name="..."> </OBJECT> Scriptlet: <OBJECT> id="TopTen" data="TopTen.htm" width="..." height="..." type="text/x-scriptlet" </OBJECT> That's it...let me know what you think! AcknowledgementsFor a good book/examples check out Scriptlets and for the examples in the book, go to Examples
|
||||||||||||||||||||||||||||||||