UpdatePanel + Update mehod

Discussion in 'ASP .Net' started by sandrofurlan, Feb 4, 2008.

  1. sandrofurlan

    sandrofurlan Guest

    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>
    sandrofurlan, Feb 4, 2008
    #1
    1. Advertising

  2. 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" 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>
    >
    Milosz Skalecki [MCAD], Feb 5, 2008
    #2
    1. Advertising

  3. sandrofurlan

    sandrofurlan Guest

    On 5 Feb, 01:27, Milosz Skalecki [MCAD] <>
    wrote:
    > 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" 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>


    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
    sandrofurlan, Feb 5, 2008
    #3
  4. sandrofurlan

    aishev Guest

    Re: Re: UpdatePanel + Update mehod

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

    > On Monday, February 04, 2008 7:27 PM mily24 wrote:


    > 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" wrote:



    >> 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>



    >>> On Wednesday, February 06, 2008 6:06 AM sandrofurlan wrote:


    >>> On 5 Feb, 01:27, Milosz Skalecki [MCAD] <>
    >>> 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
    aishev, Apr 24, 2011
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Remy
    Replies:
    0
    Views:
    2,005
  2. Vaidas Gudas

    how to update ATLAS UpdatePanel

    Vaidas Gudas, Oct 12, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    344
  3. Replies:
    3
    Views:
    479
    Rob Meade
    Aug 8, 2007
  4. =?Utf-8?B?S2V2aW4=?=

    How to know when a UpdatePanel ends a update?

    =?Utf-8?B?S2V2aW4=?=, Sep 21, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    339
  5. Nathan Sokalski
    Replies:
    1
    Views:
    587
    miher
    Jun 15, 2009
Loading...

Share This Page