views:

205

answers:

3

Hi Guys/Gals,

I have in here an old web application written in ASP.Net 2.0 + AJAX.

I have in my page a textbox control and a button and a label control which is inside an update panel.

A text will be entered into the textbox and subsequently, on the textchanged event of the control, some server side processing and data validations are involved.

I am using the label control as a display to inform the user of the progress of the validation. Different messages may appear at the label control.

In the current scenario, only the last string specified for the label control is displayed on the label control.

I am looking for ways on how to be able to display different text on the label control, say at interval of 5 seconds.

Is there an AJAX Control there for this (or something similar which I could use), where I could specify the text to be displayed at n interval of seconds?

How do I achieve this? Inputs highly appreciated. Thanks.

Edited I think I may need to re-phrase this question to make it simpler.

After an asp.net page post back, how would I be able to specify different text string in a label control which should display after every n seconds?

Like

Label1.Text = "Message 1"

.. Delay 5 seconds

Label1.Text = "Next Message"

.. Delay 5 seconds

Label1.Text = "Another Message"

.. Delay 5 seconds

Label1.Text = "Last Message"

In the current post back model (which includes AJAX UpdatePanel), only the last message is displayed.

Kindly advise. Thanks.

A: 

Try the UpdateProgress control, it's an ASP.NET AJAX server control that lets you to give feedback on the progress of an UpdatePanel rendering. You could hook it up to your label and change the text to reflect the progress of partial-postback.

cxfx
This does not suffice much to my need since the text I need to display is coming from the server-side validation of the page's data. I need to specifically display some messages using the label control (or any other control) at difference of specific seconds.For example, I may need to display the following texts:1. Processing2. Data validated3. User is AuthenticatedI am looking for a control or function where I specify the messages to display at n interval of seconds, sort of like:Function DisplayMsg(Msg1 as String, Msg2 as String, Msg3 as String, Interval as Integer)
Batuta
A: 

If the label control is contained in the update panel, then call your code using a System.Timers.Timer

Dim WithEvents timer As New System.Timers.Timer()
Dim msgStack As Stack(Of String) = Nothing

Sub DisplayMsg(ByVal msg() As String, ByVal interval As Integer)
    msgStack = New Stack(Of String)
    For i As Integer = 0 To msg.Length - 1
        msgStack.Push(msg(i))
    Next

    timer.Interval = interval
    timer.AutoReset = True
    timer.Start()
End Sub

Private Sub timer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles timer.Elapsed
    If msgStack.Count > 0 Then
        Label1.Text = msgStack.Pop()
    Else
        timer.Stop()
    End If
End Sub

Order your message input list last status message to first status message

Sub DoOperation()
    DisplayMsg(New String() {"LastMessage", "Second Message", "First Message"}, 5000)
End Sub
Charlie Brown
Tried this but did not worked out for me. I must be missing something. Kindly elaborate further. Thanks.
Batuta
A: 

If you only need to display static texts with no real connection to what's really going on a simple javascript like this will probably suffice:

var i = 0;
var strings = new Array("authenticating", "validating", "1", "2", "3", "4", "5");
var id = setInterval(function() 
  {
     document.getElementById('label').innerHTML = strings[i];
     i++;
     if (i > strings.length - 1) {clearInterval(id)} 
  }, 5000);

However if you need this to display what's really going on then I'd recommend using a webservice and AJAX.

Maybe this isn't the neatest way to do it, but I'd do it something like this:

When you start processing your request you stick a progress object into a static list with a Guid as the identifier. Then you update the state of this progress object when the progress changes.

To get the progress through javascript you build a webservice that looks something like this that you can then query in the setInterval bit of the previous codesnippet.

[WebMethod]
 public string getProgress(string guidAsString)
 {
  Guid progressId = new Guid(guid);
  switch (Progresses.progresses.Where(g => g.ProgressId == progressId).FirstOrDefault().progressState)
  {
   case state.Validating:
    return "Validating";
   case state.Authorizing:
    return "Authorizing";
   case state.LoggingIn:
    return "Logging in";
   default:
    return "";
  }
 }
Oscar Kilhed