Ajax| Timing | data | database | refresh | No refresh we may have a general impression of Atlas in connection with the last Hello,world Basic Atlas program. Then we have to start to achieve our goals: A random display of data in a database and a press button to display a single piece of data in a database without refreshing at timed intervals.
Mode: ASP. NET client control. (We know that asp.net is a server-side control.) The client's control is the previous normal HTML form control. For server-side implementations we'll fix them the next time. In fact, our previous implementation is based on the implementation of the client if you want to combine with asp.net we have to change another way, of course, Atlas is to provide Server-side controls to implement AJAX applications on the server side.
Through the last article, we know that in fact, the AJAX implementation of Atlas is to use a client's JS code plus a server-side Web service (I think Microsoft will consider for itself, build an atlas application can use the Web service )
Now let's start writing our code.
Page code:
Program code
<form id= "Formrefresh" runat= "Server" >
<div>
<div id= "ENGCNB" ><div id= "FAMOUSDIVB" class= "ALDIVB" ><a "href =" http://www.flysblog.com "target=" _ Blank "> Tianya Road Far </a>---June in the horizon, Tianya in my heart." -----to build </div></div>
function startfamous ()
{
Dosearchtimer ();
Window.setinterval ("Dosearchtimer ()", engctime*1000);
}
function Dosearchtimer ()
{
Samples.AspNet.getFamousService.getFamous (Onrequestcompletetimer);
}
function Onrequestcompletetimer (Result)
{
Changefamous (result);
}
function Dosearch ()
{
var Srchelem = document.getElementById ("Searchkey");
Samples.AspNet.getFamousService.getFamous (Onrequestcomplete);
}
function Onrequestcomplete (Result)
{
Document.formrefresh.txtFamous.value = result;
}
As usual, we create a new Web service code as follows
Program code
Using System;
Using System.Web;
Using System.Collections;
Using System.Web.Services;
Using System.Web.Services.Protocols;
Using System.Data;
Using System.Data.OleDb;
Namespace Samples.aspnet
{
<summary>
Summary description of HelloWorldService
</summary>
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
public class GetFamousService:System.Web.Services.WebService
{
Public Getfamousservice ()
{
If you are using a design component, uncomment it to follow the line
InitializeComponent ();
}
[WebMethod]
public string getfamous ()
{
String inputstring = Server.HTMLEncode (query);
if (! String.IsNullOrEmpty (inputstring))
//{
Return String.Format ("Hello, your queried for {0}.") The "
+ "Current time is {1}", InputString, DateTime.Now);
//}
Else
//{
Return "The query string is null or empty";
//}
String db = Server.MapPath ("Famousdb/famous.mdb");
int Uidd = 1;
OleDbDataReader rd = null;
OleDbConnection conn = null;
Try
{
System.Random r = new Random ();
Uidd = R.next (1,69);
String sql = "SELECT top 1 * from famous where id=" + Uidd. ToString ();
conn = new OleDbConnection (@ "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + db + ";");
Conn. Open ();
OleDbCommand cmd = new OleDbCommand (SQL, conn);
rd = cmd. ExecuteReader ();
if (Rd. HasRows)
{
Rd. Read ();
Return rd[1]. ToString ();//Response.Write (@ "<querys><famous><![ cdata["+ rd[1]. ToString () + @ "]]></famous></querys>");
} else {
return "null";//response.write (@ "<querys><famous><![ Cdata[null]]></famous></querys> ");
}
}
Finally
{
Always call Close is done reading.
Rd. Close ();
Always call Close is done reading.
Conn. Close ();
}
}
}
}
In fact, the whole process is exactly the same as the last Hello,world Atlas program. is to change the function in the Web service.
Here you can run the program you created or run the Code program I provided. You'll find that the implementation is exactly the same as the small frame you built.
Summarize
This Atlas client application feels like Microsoft does not have the AJAX framework of Ajax.NET Pro, which implements the client's JS code to invoke the server-side function code directly, but through the intermediary web Service. Although Ajax.NET Pro makes me very depressed. But it is very good to call the server-side method directly (although I myself did not debug the code, only implemented a simple character return, did not implement the database read). Next application we will use server-side controls to implement this application.
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.