question

Sygrien-8682 avatar image
0 Votes"
Sygrien-8682 asked Sygrien-8682 commented

Why is the form not refreshed ?

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



dotnet-aspnet-webpages
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Maybe you should also execute Me.lblDHRafraîchissement.Text = String.Format...?


0 Votes 0 ·

Thanks Viorel for your answer.
No, adding the date info doesn't make the refresh...

Is there a command which instructs asp.net to refresh the form on the server ?

0 Votes 0 ·
Bruce-SqlWork avatar image
1 Vote"
Bruce-SqlWork answered Sygrien-8682 commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you Bruce !!

All I needed was the "Autoback" property in my Dropdown list !!
Thanks again !

0 Votes 0 ·
YijingSun-MSFT avatar image
0 Votes"
YijingSun-MSFT answered Sygrien-8682 commented

Hi @Sygrien-8682 ,
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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks YijingSun !
Your comments are very highly appreciated!
I already selected the answer from Bruce, so I can't select yours as well. But it is very informative. thanks again !

0 Votes 0 ·