can this be done

d2005

Active member
Joined
Aug 31, 2005
Messages
37
Location
ireland
Programming Experience
Beginner
i have two functions a
VB.NET:
Public Sub refereshparent() Dim NewScript As String NewScript = "<script language=JavaScript>" NewScript = NewScript + "window.parent.location.href = window.parent.location.href;" NewScript = NewScript + "</script" + ">" If (Not IsClientScriptBlockRegistered("test")) Then RegisterClientScriptBlock("test", NewScript) End If End Sub
VB.NET:
Private Sub alert() Dim strmessage As String strmessage = " alerting user" Dim strscript As String = "<script language=JavaScript>" strscript += "alert(""" & strmessage & """);" strscript += "</script>" If (Not Page.IsStartupScriptRegistered("clientScript")) Then Page.RegisterStartupScript("clientScript", strscript) End IfEnd sub
can i have this so that when i click ok in the alert
it shall call the refereshparent
if i call the refresh in the alert()

the page refreshes with no alert being shown
where as i though that all operations were stopped until the user clicked ok

is it possible to sow the alert
then perform the refershparent when they click ok

thanks in advance
 
First remember that the refreshparent() and alert() subs are running on the server. All they are doing is writing your javascript to the page in the Page.RegisterStartupScriptBlock and Page.RegisterClientScriptBlock.

Because you used RegisterStartupScriptBlock for the alert/msgbox, you will see the javascript alert as soon as the page loads in the users browser. The RegisterStartupScriptBlock only writes the javascript to the page, but does not have it start after the page loads in the browser. To get the functionality you are looking for you need to call the function after the alert is dismissed. Also you only want to display it if the user click 'ok' right? so change the alert to a confirm. In summary, I would recommend changing your subs to this:

Public Sub refereshparent()
Dim NewScript As String NewScript = "<script language=JavaScript>"
NewScript = NewScript + "function refreshParentJS(){window.parent.location.href = window.parent.location.href;}"
NewScript = NewScript + "</script" + ">"
If (Not IsClientScriptBlockRegistered("test")) Then
RegisterClientScriptBlock("test", NewScript)
End If
End Sub

Private Sub alert()
Dim strmessage As String
strmessage = " alerting user"
Dim strscript As String = "<script language=JavaScript>"
strscript += "bConfirmed = window.confirm(""" & strmessage & """);"
strscript += "if(bConfirmed){refreshParentJS();}"
strscript += "</script>"
If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strscript)
End If
End sub
 
Back
Top