Nothing is simpler than creating a basic project in AJAX ASP.NET, once the environment is prepared as we saw in the previous chapter, and given that we have a template for it, we will not complicate our lives to get started:

This will create a structure as follows:

Nothing out of this world, right? a Default, a web.config and the DLL to use the simple AjaxControlToolkit. Now that we have used the template, let’s go a little deeper to see what it has created for us compared to a normal ASP.NET project.

 DEFAULT.ASPX

As we see, we do not have anything special to highlight except for the ScriptManager, which we could say is the heart of AJAX ASP.NET, it will be the one in charge of managing our components, therefore we will always have to have one on our page. <%@PageLanguage=“C#“AutoEventWireup=“true"CodeFile=“Default.aspx.cs"Inherits=”_Default” %> <htmlxmlns=“http://www.w3.org/1999/xhtml"> <headrunat=“server”> <title>Untitled Page</title> </head> <body> <formid=“form1"runat=“server”> asp:ScriptManagerID\="ScriptManager1"runat\="server"/ <div> </div> </form> </body> </html>

As we said in the talk the other day, let’s all repeat, ScriptManager is our Goddess, oh!! Let’s not forget our ScriptManager!! Here in your design view:

If we have real changes, it is with the web.config, which has been configured to be able to work with AJAX.

We also see that in the toolbar we have a new section:

Well, for our first application we will simply drag the UpdatePanel component and a Timer to the page, and inside it we will put a label, and in the Timer we change the Interval parameter to 1000 and define a Tick event, at the code level we would have something like this:

<formid=“form1"runat=“server”>     asp:ScriptManagerID\="ScriptManager1"runat\="server"/     <asp:TimerID=“Timer1"runat=“server"Interval=“1000” OnTick=“dameHora” >     </asp:Timer>     <div>         It is         asp:UpdatePanelID\="UpdatePanel1"runat\="server"             <ContentTemplate>                asp:LabelID\="lblHora"runat\="server"</asp:Label>         </ContentTemplate>         asp:LabelID\="lblHora"runat\="server"</asp:Label>         </ContentTemplate>         </asp:UpdatePanel>    </div> </form>

Now we just have to tell him what he is going to do when the Timer goes off.

protectedvoid dameTime(object sender, EventArgs e) { lblTime.Text = DateTime.Now.ToLongTimeString(); }

READY !! We have already created our first application that changes by itself and tells us the time at every moment. Yes, yes, I know, we did that with a crappy script years ago, don’t despair, this is just the first step, imagine that what it does is collect some RSS or data from a webservice, or……