Recently, many people on the CSDN Forum asked about ajax in ASP. NET applications, and problems are constantly being mentioned. Many experts have also published many professional technical documents. I am also ugly today, and I will give you a simple and easy-to-understand example...
First, we will introduce several professional terms:
Ajax: AJAX is "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML). AJAX is not a acronym, but a term created by Jesse James Gaiiett, this is a web development technology used to create interactive web applications.
Common Ajax controls in Visual studio 2008:
ScriptManager control: Manages Ajax server controls in pages and is the core control of Ajax.
UpdatePanel control: Implements asynchronous update of containers so that server controls that cannot be asynchronously updated implement Ajax functions.
Timer control: Timer is a Timer, but it is not only difficult but also resource-consuming in ASP.net.
After the component is introduced, paste the following code:
Front-end Html code and server-side controls
Html code
<Form id = "form1" runat = "server">
<Asp: ScriptManager ID = "ScriptManager1" runat = "server">
</Asp: ScriptManager>
<Asp: Timer ID = "Timer1" runat = "server" ontick = "Timer1_Tick">
</Asp: Timer>
<Div>
<Asp: UpdatePanel ID = "UpdatePanel1" runat = "server">
<Triggers>
<Asp: AsyncPostBackTrigger ControlID = "Timer1" EventName = "Tick"/>
</Triggers>
<ContentTemplate>
<Asp: Label ID = "Label1" runat = "server" Text = "Label"> </asp: Label>
</ContentTemplate>
</Asp: UpdatePanel>
</Div>
</Form>
Background C # code
Csharp code
Protected void Page_Load (object sender, EventArgs e)
{
Databing ();
}
Protected void timereffectick (object sender, EventArgs e)
{
Timer1.integer = 5000;
}
Private void databing ()
{
Label1.Text = DateTime. Now. ToString ();
}
To dynamically update pages within 5 seconds, it is not necessarily possible to achieve this at the beginning of the operation because of the high overhead.
Timer1.integer = 5000
The value here is the number of milliseconds, 1 second = 1000 milliseconds
This article is from weiqiao"