Solved

How to use javascript in back code (.aspx.vb)?

Posted on 2008-10-03
1
1,060 Views
Last Modified: 2012-05-05
Hi,

Below I'm trying to avoid a refresh of a page by using a session variable and a redirect. However when the redirection occurs I want a javascript message coming up saying that a refresh is not allowed. I found a neat method called ClientScript.RegisterStartupScript, but it doesnt seem to execute even though the redirection occurs. Can anyone spot anything I'm doing wrong?

If Page.IsPostBack = False Then

            If Session("page_loaded") = "YES" Then

                Dim onloadScript As New System.Text.StringBuilder()
                onloadScript.Append("<script type='text/javascript'>")
                onloadScript.Append(vbCrLf)
                onloadScript.Append("alert('Refresh not allowed');")
                onloadScript.Append(vbCrLf)
                onloadScript.Append("</script>")
                ' Register script with page
                Me.ClientScript.RegisterStartupScript(Me.GetType(), "onLoadCall", onloadScript.ToString())

                Response.Redirect("index.aspx")

            Else
               //code to be executed the first time
               
                Session("page_loaded") = "YES"

            End If


        Else

            Dim onloadScript As New System.Text.StringBuilder()
            onloadScript.Append("<script type='text/javascript'>")
            onloadScript.Append(vbCrLf)
            onloadScript.Append("alert('Refresh not allowed');")
            onloadScript.Append(vbCrLf)
            onloadScript.Append("</script>")
            ' Register script with page
            Me.ClientScript.RegisterStartupScript(Me.GetType(), "onLoadCall", onloadScript.ToString())

            Response.Redirect("index.aspx")


        End If
0
Comment
Question by:Gary2Seven
1 Comment
 
LVL 13

Accepted Solution

by:
joechina earned 125 total points
ID: 22634606
try
remove
Response.Redirect("index.aspx")

update
onloadScript.Append("alert('Refresh not allowed');")
to
onloadScript.Append("alert('Refresh not allowed');window.location ='index.aspx';")


0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question