0

I have a <asp:Label ID="ceckSlide"/> in my aspx page and would like to update this label constantly form a class in my model so that the label keeps changing based on a for loop. I would like to know if this is possible, if so how would I go about doing this,

As can be seen from the pseudo-code, I am calling the add services method in the aspx page, and would like to update the table in accordance with the for loop in createServices class.

class CreateServices

private int number = 0
priavte int numbercount = 0;

public void addservices()
{
   numbercount = services.count;

   for(int i = 0;i<service.count;i++)
   {
      ///add services 
      number = i+1;
   }
}

public int GetNumber()
{
    int number= number;
    return slide;
}
public int GetSlideCount()
{

    return numberCount;
}

defefaul.aspx

protected void Confirm_Click(object sender, EventArgs e)
{
   var ser =  new CreateServices();
   var addSer = ser.addservices()
}

// label get updated in this method in the aspx file 
protected void GetSlideNumber()
{

    var ser =  new CreateServices();
    int number= ser .GetSlideNumber();
    int numberCount = ser.GetSlideCount() + 1;

    ceckSlide.Text = slide.ToString() +" Of "+slideCount;
 }
4
  • 2
    The client requests a page, not the server updates the client. Commented Feb 12, 2013 at 10:36
  • Could you include more code and explain what exactly you would like to achieve? Commented Feb 12, 2013 at 10:36
  • @TimSchmelter, not necessarily true, see Comet :) Commented Feb 12, 2013 at 10:37
  • I have added more detail Commented Feb 12, 2013 at 10:51

3 Answers 3

1

The easiest way for you is to put your label in an UpdatePanel (AJAX) and place a client-side timer (javascript) in your page that sends an update request every few seconds (or whatever you wish). On the server-side, simply update your Model asynchronously and the function that updates the label value should read from the Model directly. Hope that helps.

Sign up to request clarification or add additional context in comments.

6 Comments

that didnt really help becuase i still dont understand it, will this work in conjuntion with thw for loop
Add more detail to your question. We don't know what your label is displaying, where is it getting updated and what's the role of your for loop in all this.
is that enough detil that i am giving you
+1 @user2061088 - If you want a "live" table in the client's browser (where the user is able to see the updates in "real time"), then this is a good suggestion on how to approach the problem. SO isn't meant to be a code exchange site, so this likely the best answer you'll get.
|
0

You might want to take a look at the PokeIn Library - ASP.NET WebSocket & Comet Ajax Library (Reverse Ajax - Server Push).

From the documentation webpage:

... PokeIn generates dynamic JavaScript codes from a .NET class to let you call them like you are calling a method from same side.

1 Comment

I think that more obfuscation of the Request/Response cycle doesn't do any good for someone who doesn't seem to understand it in the first place.
0

I think the issue is that you don't quite understand how the HTTP protocol works. HTTP uses a Request/Response model, where the client (typically a web browser) makes a request and then the server responds.

The typical architecture used when implementing the auto-updating feature you are describing is exactly what @dotNET has described - the client-side page has some bit of javascript which automatically fires off a request at set intervals. The server responds with the updated state. You can make this interval as small as you'd like, though shorter intervals will sometimes cause problems for users with either slow machines or slow internet connections.

While a simple web application can be developed without much knowledge of the Request/Response cycle, more advanced development (like what you are describing) practically requires that you have a thorough understanding of the web's architecture. If you don't understand the HTTP protocol, I recommend that you take some time to learn it - the small investment will pay huge dividends in how effective and effecient your code will be. REST is a good place to start because its recommendations adhere most closely to the HTTP specification.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.