Solved

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

Posted on 2008-10-03
1
1,065 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 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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