473,327 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Simple ajax problem?

I'm trying to follow the instructions on
http://www.asp.net/learn/videos/view...tabid=63&id=75 for a simple AJAX
demo.

However, my code updates all 3 labels even though only 1 of them is inside
an UpdatePanel. What am I not doing that the presenter is?

Here's the my ASPX and codebehind code..

ASPX
------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SimpleAjax.aspx.cs"
Inherits="Forms_SimpleAjax" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<asp:Label ID="label1" runat=server></asp:Label>&nbsp;<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="label2" runat=server></asp:Label>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:Label ID="label3" runat=server></asp:Label>
<br />
<br />
</div>
</form>
</body>
</html>

Codebehind
--------------

public partial class Forms_SimpleAjax : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
label2.Text = DateTime.Now.ToString();
label3.Text = DateTime.Now.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{

}
}

May 22 '07 #1
3 1213
protected void Page_Load(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
label2.Text = DateTime.Now.ToString();
label3.Text = DateTime.Now.ToString();
}
Everytime you load your page, you are updating all three buttons again via
the Page_Load event.

I haven't ran through the tutorial, but I bet that if you surround that code
(the three label lines) with:

if (!Page.IsPostBack)
{

-- code here --

}

It'll fix your problem. That code above basically says "If it's NOT a Page
Postback (aka: this is your FIRST page load), then populate the labels..."

HTH.

-dl

---
David R. Longnecker
Web Developer
http://blog.tiredstudent.com
I'm trying to follow the instructions on
http://www.asp.net/learn/videos/view...tabid=63&id=75 for a simple
AJAX demo.

However, my code updates all 3 labels even though only 1 of them is
inside an UpdatePanel. What am I not doing that the presenter is?

Here's the my ASPX and codebehind code..

ASPX
------
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="SimpleAjax.aspx.cs" Inherits="Forms_SimpleAjax" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Label ID="label1" runat=server></asp:Label>&nbsp;<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="label2" runat=server></asp:Label>
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click"
Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:Label ID="label3" runat=server></asp:Label>
<br />
<br />
</div>
</form>
</body>
</html>

Codebehind
--------------
public partial class Forms_SimpleAjax : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
label2.Text = DateTime.Now.ToString();
label3.Text = DateTime.Now.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}

May 22 '07 #2
Thanks anyway, but that's not it. double checked the tutorial and the author
didn't do that. If you wrap the code, it will only populate the labels the
first time in.

"David Longnecker" wrote:
protected void Page_Load(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
label2.Text = DateTime.Now.ToString();
label3.Text = DateTime.Now.ToString();
}

Everytime you load your page, you are updating all three buttons again via
the Page_Load event.

I haven't ran through the tutorial, but I bet that if you surround that code
(the three label lines) with:

if (!Page.IsPostBack)
{

-- code here --

}

It'll fix your problem. That code above basically says "If it's NOT a Page
Postback (aka: this is your FIRST page load), then populate the labels..."

HTH.

-dl

---
David R. Longnecker
Web Developer
http://blog.tiredstudent.com
I'm trying to follow the instructions on
http://www.asp.net/learn/videos/view...tabid=63&id=75 for a simple
AJAX demo.

However, my code updates all 3 labels even though only 1 of them is
inside an UpdatePanel. What am I not doing that the presenter is?

Here's the my ASPX and codebehind code..

ASPX
------
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="SimpleAjax.aspx.cs" Inherits="Forms_SimpleAjax" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Label ID="label1" runat=server></asp:Label<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="label2" runat=server></asp:Label>
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click"
Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:Label ID="label3" runat=server></asp:Label>
<br />
<br />
</div>
</form>
</body>
</html>

Codebehind
--------------
public partial class Forms_SimpleAjax : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
label2.Text = DateTime.Now.ToString();
label3.Text = DateTime.Now.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}


May 22 '07 #3
Just to follow-up on my previous post. This project is converted from
ASP.NET 1.1 which I didn't think would be an issue.

But If I create a new website from scratch using the "ASP.NET AJAX-Enabled
Website" project template, I get a different problem when using the same code:

"Microsoft JScript runtime error: Object doesn't support this property or
method"
in the MicrosoftAjax.js file with references to the following js methods...

return function() {
return method.apply(instance, arguments);
}

and on the line where this is called...

this._xmlHttpRequest.open(verb, this._webRequest.getResolvedUrl(), true );

"Dave" wrote:
I'm trying to follow the instructions on
http://www.asp.net/learn/videos/view...tabid=63&id=75 for a simple AJAX
demo.

However, my code updates all 3 labels even though only 1 of them is inside
an UpdatePanel. What am I not doing that the presenter is?

Here's the my ASPX and codebehind code..

ASPX
------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SimpleAjax.aspx.cs"
Inherits="Forms_SimpleAjax" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<asp:Label ID="label1" runat=server></asp:Label<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="label2" runat=server></asp:Label>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:Label ID="label3" runat=server></asp:Label>
<br />
<br />
</div>
</form>
</body>
</html>

Codebehind
--------------

public partial class Forms_SimpleAjax : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
label2.Text = DateTime.Now.ToString();
label3.Text = DateTime.Now.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{

}
}
May 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: dondraper | last post by:
I have an application that uses a popular but simple set of JavaScript routines that implement an AJAX call used to populate a drop-down. It works for thousands of user but I have one customer...
2
by: Alex | last post by:
Example uploaded to: http://www.clickatus.com/ajax/ BTW - This is for FIREFOX, won't work in IE. I don't know why but when it is executed the browser still in loading state... Even though...
7
by: Ivan Marsh | last post by:
Hey Folks, I'm having a heck of a time wrapping mind around AJAX. Anyone know of a simple, straight-forward example for pulling a simple query from mysql with PHP using AJAX? As I...
3
by: Alok yadav | last post by:
I have an open IP and on that IP our main application is hosted. it uses ajax. in web.config file i have register ajax handlers. there are also other sites or project on that IP. now my problem is...
1
by: www.web20developers.com | last post by:
http://www.web20developers.com http://www.web20developers.com/index.php?option=com_content&task=view... Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell AJAX -...
1
by: Boris Twila | last post by:
I just want to have 1 drop down list fill the other drop down list without a round trip. Is there some really simple ajax thing i can copy and use, or is it a big deal do i habe to install an...
0
by: minnie | last post by:
An AJAX Simple Example for PHP Article from http://www.joyistar.com Introduction: AJAX WebShop 3 Beta2 supports PHP programming by integrating PHP5 development environment. Here we will give an...
3
by: equazcion | last post by:
Hi, I have an image reference (IMG) in my page that changes depending on the value of a database field. Clicking the image triggers an Ajax call to change the database field (toggles the field...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.