Why is the form not refreshed ?

Sygrien 21 Reputation points
2022-07-07T09:01:42.92+00:00

I'm writing my first asp.net application.

I have developped a form which shows constantly changing data .

On my form, I have a timer which refreshes the form at regular intervals. This works fine. I have simply programmed this via code-behind (in VB).

    Private Sub monTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles monTimer.Tick  
        AfficheDonnéesMachine()  
        Me.lblDHRafraîchissement.Text = String.Format("Données du {0} à {1}.", DateTime.Now.ToShortDateString, DateTime.Now.ToShortTimeString)  
    End Sub  
  

I also have a dropdown control. When the user changes a value in the dropdown, I want the form to be refreshed as well. But it doesn't work...

    Protected Sub ListeMachines_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListeMachines.SelectedIndexChanged  
        AfficheDonnéesMachine()  
    End Sub  

I would like to find a simple way to show the new values of the form. Thanks

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,170 questions
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 52,496 Reputation points
    2022-07-07T15:24:04.343+00:00

    Webforms is a simple single request and single response. The server can not update the browser after the page response. To do what you want, the timer must be in the browser, and make a new request. This is done with the refresh meta tag or JavaScript.

    The webform event will not happen until the browser posts the form. This will cause the page processing and events to be called. I believe the dropdown has an auto post back feature, which generates JavaScript to do a form submit on change. This will send the from data to the server, the server will process the form data, and create a new page which the browser displays.

    note: this is a webform question and should be asked in the asp.net web forms section, not the newer asp.net core

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,061 Reputation points
    2022-07-08T06:14:14.133+00:00

    Hi @Sygrien ,
    Maybe you can add this line in your aspx after the head tag:

    <m eta http-equiv="Refresh" content="2" />  
    

    This would refresh page after every 2 seconds.

    Or if you want to do it in code behind do it like this:

    R esponse.AppendHeader("Refresh", "2");  
    

    Best regards,
    Yijing Sun


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.