Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net web application 3 58
ASP.NET MVC - Views 3 61
How to repeat the data 4 43
Issue in displaying table columns on selection of dropdown 2 27
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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