?
Solved

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

Posted on 2008-10-03
1
Medium Priority
?
1,067 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 13

Accepted Solution

by:
joechina earned 375 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

719 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