Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: 17 Mar 2005 04:47:18 -0800,    group: microsoft.public.dotnet.framework.aspnet.webcontrols        back       


RegisterStartupScript problem   
Hi ,

 i am using vbscript to open word document in my web page.(web page
is written in c# )
  The code snippet in below. This code is doing what i want.
however when i try
 to go back opener page with internet explorer "Back" button this
 function is working again and word document is opening so i could
not  open my page again.Is there any solution to unregister or block
this script...

        string redirect  = "c:/NewFolder/xxx.doc";
        script = "<SCRIPT language='vbScript'>"
                + " window.location=\"" + redirect + "\""
                + " '</SCRIPT>";
        Page.RegisterStartupScript("__JS_OPENFILE",script);

thanks..
date: 17 Mar 2005 04:47:18 -0800   author:   (Kaan Acar)

Re:RegisterStartupScript problem   
While you cannot unregister a script, you can re-register the script and 
have the function do nothing.  See the example code below.  This could 
turned on or off when PagePostBack == false.

if (turnOn == true)
{
	sbAlertScript.Append("<script language='javascript'>\n");
	sbAlertScript.Append("function ShowMessageOfTheDay()\n");
	sbAlertScript.Append("{\n");
	sbAlertScript.Append("alert(\"" + message + "\");\n");
	sbAlertScript.Append("}\n");
	sbAlertScript.Append("</script>\n");

	Page.RegisterStartupScript("alertScript", sbAlertScript.ToString());
}
else
{
	sbAlertScript.Append("<script language='javascript'>\n");
	sbAlertScript.Append("function ShowMessageOfTheDay()\n");
	sbAlertScript.Append("{\n");
	sbAlertScript.Append("\n");
	sbAlertScript.Append("}\n");
	sbAlertScript.Append("</script>\n");
	Page.RegisterStartupScript("alertScript", sbAlertScript.ToString());	
}

--------------------------------
From: Greg Finzer
<a href="http://www.kellermansoftware.com">Kellerman Software</a>
date: Fri, 23 Dec 2005 10:15:30 -0600   author:   Greg Finzer

Re: RegisterStartupScript problem   
While you cannot unregister a script, you can re-register the script and
have the function do nothing.  See the example code below.  This could
turned on or off when PagePostBack == false.

if (turnOn == true)
{
	sbAlertScript.Append("<script language='javascript'>\n");
	sbAlertScript.Append("function ShowMessageOfTheDay()\n");
	sbAlertScript.Append("{\n");
	sbAlertScript.Append("alert(\"" + message + "\");\n");
	sbAlertScript.Append("}\n");
	sbAlertScript.Append("</script>\n");

	Page.RegisterStartupScript("alertScript", sbAlertScript.ToString());
}
else
{
	sbAlertScript.Append("<script language='javascript'>\n");
	sbAlertScript.Append("function ShowMessageOfTheDay()\n");
	sbAlertScript.Append("{\n");
	sbAlertScript.Append("\n");
	sbAlertScript.Append("}\n");
	sbAlertScript.Append("</script>\n");
	Page.RegisterStartupScript("alertScript", sbAlertScript.ToString());	
}

--------------------------------
From: Greg Finzer
'Kellerman Software' (http://www.kellermansoftware.com)


-- 
gfinzer
------------------------------------------------------------------------
gfinzer's Profile: http://www.highdots.com/forums/m1623
View this thread: http://www.highdots.com/forums/t707352
date: Fri, 23 Dec 2005 17:22:43 +0100   author:   gfinzer

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

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us