UpdatePanel + Update mehod

S

sandrofurlan

Hi everybody,
I've a problem with an updatepanel.
I'd like to show progress value (from 1 to 10) shown on my form
without page refresh (using Ajax UpdatePanel).
Serialization starts from Serialize button event
Then in the script code section I increment label text value in a for
cycle. But on the video there's no refresh.
I also add a thread.sleep for 1 sec

I post the (simply) code, hope somebody help me:

<%@ Page Language="C#" %>

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

<script runat="server">

protected void Serialize_Click(object sender, EventArgs e)
{
for (int i = 1; i < 10; i++)
{
Label1.Text = Convert.ToString(i);
UpdatePanel1.Update();
System.Threading.Thread.Sleep(1000);

}
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="Serialize" Text="Serialize" runat="server"
OnClick="Serialize_Click" />
<br />
<asp:Label ID="Label1" runat="server" Text="1"
AutoPostBack="true" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
 
M

Milosz Skalecki [MCAD]

Howdy,

I think you're missing the point. Update method just marks the update panel
to be rerenderd on the client site with the content generated on the server.
I'm not sure how familiar with the UpdatePanel concept you are, in order to
use it properly you need to understand the key thing: page with a update
panel works almost the same as it would without it (simplifying, Page class
is instantiated, OnInit, OnLoad, ViewState, etc, which is usual lifecycle,
then HTML is written to a response buffer, that is filtered by AJAX framework
to get HTML for the div being updated). Now in order to make it work, you
need to use Timer control in conjunction with UpdatePanel:

<asp:ScriptManager runat="server" ID="scriptManager" />
<asp:UpdatePanel runat="server" ID="panel" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" ID="progress" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer runat="server" ID="timer" Enabled="false" Interval="1000"
OnTick="timer_Tick" />
<asp:Button runat="server" ID="start" Text="Start!" OnClick="start_Click" />

<script runat="server">
protected void start_Click(object sender, EventArgs e)
{
Counter = 0;
timer.Enabled = true;
}
protected void timer_Tick(object sender, EventArgs e)
{
Counter++;
progress.Text = Counter.ToString();

if (Counter >= 10)
{
timer.Enabled = false;
progress.Text = "Done";
}
}
protected int Counter
{
get
{
object value = ViewState["Counter"];
return value == null ? 0 : (int)value;
}
private set
{
ViewState["Counter"] = value;
}
}
</script>

In addition, you need to implement a task execution separately. Please let
me know if you need a clue on that.

Regards
 
S

sandrofurlan

Howdy,

I think you're missing the point. Update method just marks the update panel
to be rerenderd on the client site with the content generated on the server.
I'm not sure how familiar with the UpdatePanel concept you are, in order to
use it properly you need to understand the key thing: page with a update
panel works almost the same as it would without it (simplifying, Page class
is instantiated, OnInit, OnLoad, ViewState, etc, which is usual lifecycle,
then HTML is written to a response buffer, that is filtered by AJAX framework
to get HTML for the div being updated). Now in order to make it work, you
need to use Timer control in conjunction with UpdatePanel:

<asp:ScriptManager runat="server" ID="scriptManager" />
<asp:UpdatePanel runat="server" ID="panel" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" ID="progress" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer runat="server" ID="timer" Enabled="false" Interval="1000"
OnTick="timer_Tick" />
<asp:Button runat="server" ID="start" Text="Start!" OnClick="start_Click" />

<script runat="server">
protected void start_Click(object sender, EventArgs e)
{
Counter = 0;
timer.Enabled = true;
}
protected void timer_Tick(object sender, EventArgs e)
{
Counter++;
progress.Text = Counter.ToString();

if (Counter >= 10)
{
timer.Enabled = false;
progress.Text = "Done";
}
}
protected int Counter
{
get
{
object value = ViewState["Counter"];
return value == null ? 0 : (int)value;
}
private set
{
ViewState["Counter"] = value;
}
}
</script>

In addition, you need to implement a task execution separately. Please let
me know if you need a clue on that.

Regards
--
Milosz

sandrofurlan said:
Hi everybody,
I've a problem with an updatepanel.
I'd like to show progress value (from 1 to 10) shown on my form
without page refresh (using Ajax UpdatePanel).
Serialization starts from Serialize button event
Then in the script code section I increment label text value in a for
cycle. But on the video there's no refresh.
I also add a thread.sleep for 1 sec
I post the (simply) code, hope somebody help me:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Serialize_Click(object sender, EventArgs e)
{
for (int i = 1; i < 10; i++)
{
Label1.Text = Convert.ToString(i);
UpdatePanel1.Update();
System.Threading.Thread.Sleep(1000);

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="Serialize" Text="Serialize" runat="server"
OnClick="Serialize_Click" />
<br />
<asp:Label ID="Label1" runat="server" Text="1"
AutoPostBack="true" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

Thanks Milosz,
I know I can use a timer control but it's exactly what I don't want.
I'd like to have panel control direct from code (specially I want that
the server update a div section every time I need from code and not
using a timer).
I'm not an expert of asp.net, but I think it must be possible to do
it. I want to force Update method everytime I need without timer.

Thank you
I'd tried to ask if someone knows how to implement this simple cose
without using timer
 
A

aishev

Have you find the solution?Because I had similar problem with you.
Howdy,

I think you're missing the point. Update method just marks the update panel
to be rerenderd on the client site with the content generated on the server.
I'm not sure how familiar with the UpdatePanel concept you are, in order to
use it properly you need to understand the key thing: page with a update
panel works almost the same as it would without it (simplifying, Page class
is instantiated, OnInit, OnLoad, ViewState, etc, which is usual lifecycle,
then HTML is written to a response buffer, that is filtered by AJAX framework
to get HTML for the div being updated). Now in order to make it work, you
need to use Timer control in conjunction with UpdatePanel:

<asp:ScriptManager runat="server" ID="scriptManager" />
<asp:UpdatePanel runat="server" ID="panel" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" ID="progress" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer runat="server" ID="timer" Enabled="false" Interval="1000"
OnTick="timer_Tick" />
<asp:Button runat="server" ID="start" Text="Start!" OnClick="start_Click" />

<script runat="server">
protected void start_Click(object sender, EventArgs e)
{
Counter = 0;
timer.Enabled = true;
}
protected void timer_Tick(object sender, EventArgs e)
{
Counter++;
progress.Text = Counter.ToString();

if (Counter >= 10)
{
timer.Enabled = false;
progress.Text = "Done";
}
}
protected int Counter
{
get
{
object value = ViewState["Counter"];
return value == null ? 0 : (int)value;
}
private set
{
ViewState["Counter"] = value;
}
}
</script>

In addition, you need to implement a task execution separately. Please let
me know if you need a clue on that.

Regards
--
Milosz


:
On Wednesday, February 06, 2008 6:05 AM sandrofurlan wrote:
Hi everybody,
I've a problem with an updatepanel.
I'd like to show progress value (from 1 to 10) shown on my form
without page refresh (using Ajax UpdatePanel).
Serialization starts from Serialize button event
Then in the script code section I increment label text value in a for
cycle. But on the video there's no refresh.
I also add a thread.sleep for 1 sec

I post the (simply) code, hope somebody help me:

<%@ Page Language="C#" %>

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

<script runat="server">

protected void Serialize_Click(object sender, EventArgs e)
{
for (int i = 1; i < 10; i++)
{
Label1.Text = Convert.ToString(i);
UpdatePanel1.Update();
System.Threading.Thread.Sleep(1000);

}
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="Serialize" Text="Serialize" runat="server"
OnClick="Serialize_Click" />
<br />
<asp:Label ID="Label1" runat="server" Text="1"
AutoPostBack="true" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
27, Milosz Skalecki [MCAD] <[email protected]>
wrote:

Thanks Milosz,
I know I can use a timer control but it's exactly what I don't want.
I'd like to have panel control direct from code (specially I want that
the server update a div section every time I need from code and not
using a timer).
I'm not an expert of asp.net, but I think it must be possible to do
it. I want to force Update method everytime I need without timer.

Thank you
I'd tried to ask if someone knows how to implement this simple cose
without using timer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top