|
|
|
date: 17 Mar 2005 04:47:18 -0800,
group: microsoft.public.dotnet.framework.aspnet.webcontrols
back
Re:RegisterStartupScript problem
Encountered the same problem in our ASPX project using VB.NET code behind.
RegisterStartupScript was added on a page on a click of a save button. This
script creates an ALERT message saying SAVING WAS SUCCESSFUL .
User clicks on a link sending him to another page.
On click of BACK , the alert message SAVING WAS SUCCESSFUL appears again.
What seems to have happened was it took the page from cache. Then the script
runs again . Even if you put the RegisterStartupScript on IS NOT POSTBACK
event , it will still run since the page was taken from cache and not a
postback.
THIS ONLY HAPPENS WITH IE 7 , Firefox does not run the alert message again .
WORKAROUND for IE 7
1. Create an if statement on the script to compare 2 objects containing
dates
2. 1st object located on the aspx page (textbox set to 1px so seemingly
invisible or someother way ) contains the seconds property of Now() on first
loading of page
3. 2nd object is contained within the javascript var thisdate = New Date()
getSeconds()
4. When the 2 objects (seconds) are the same , show alert else do nothing.
Alert will show only on the first time when the 1st object second property
is the same with the 2nd object second property. on redirection to another
page , and click of back button, the thisdate object second property is
already different .
This wont work only on the rare occassion when the event happened on the
split second that 1st object gets a second value and the 2nd object gets the
next incremental second value.
CODE :
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.
EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim msg As String = Request.QueryString("msg")
If msg.Length > 0 Then
MsgBox(msg)
End If
Me.TextBox1.Text = Now().Second
End If
End Sub
Private Sub MsgBox(ByVal message As String)
Dim strScript As String = ""
strScript += "<script type='text/javascript'> " & vbCrLf
strScript += "var datenow = new Date() ; " & vbCrLf
strScript += "var timenow =datenow.getSeconds();" & vbCrLf
strScript += " var timeold = document.getElementById ('TextBox1').value ;
" & vbCrLf
strScript += " if ( timenow == timeold ) " & vbCrLf
strScript += " alert(' " & message & " ') ; " & vbCrLf
strScript += "</script>"
ClientScript.RegisterStartupScript(Me.GetType, "Alert", strScript)
End Sub
SORRY if i sound amateurish.. coz i am :)
url:http://www.ureader.com/msg/1425101.aspx
date: Sun, 4 May 2008 10:50:41 +0800
author: santino
|
|