Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now