Sunday, March 11, 2012

AJAX 1.0 RC Getting started #1 Does not work for me an Ajax newbie

Did you use the AJAX template when you created a website? Check you web.confighttp://alpascual.com/blog/al/archive/2006/10/24/Manually-upgrading-from-Atlas-to-ASP.NET-2.0-Ajax.aspx

Do you mind post aspx code (HTML part only)

I should able to tell you what went wrong by looking at it

MIB426


<

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>

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>

<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>

<asp:TimerID="Timer1"runat="server"Interval="5000"OnTick="Timer1_Tick">

</asp:Timer>

</ContentTemplate>

</asp:UpdatePanel>

</div>

</form>

</

body>

</

html>

protectedvoid Page_Load(object sender,EventArgs e)

{

if (!Page.IsPostBack)

Label1.Text =

"Timer will run every 5 seconds to display the time in an Update Panel";

}

protectedvoid Timer1_Tick(object sender,EventArgs e)

{

Label1.Text =

DateTime.Now.ToString();

}


You missed few things

1.

<asp:ScriptManager ID="sm" runat="server"EnablePartialRendering=true>
</asp:ScriptManager>

2.

<asp:UpdatePanel ID="up" runat="server" >

<ContentTemplate>
<asp:Label ID="lblTime" runat="server" Height="191px" Width="422px"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer ID="Timer" runat="server" Interval="5000">
</asp:Timer>

You need trigger the UpdatePanel, so it knows when to use Ansync post back.

You also need to tell Script Manager its partial Rendering

Hope it helps~

MIB426

No comments:

Post a Comment