Solved

Problem with RegisterStartupScript

Posted on 2011-02-12
2
479 Views
Last Modified: 2012-05-11
Hi Experts

I use this code on many forms with out any problems:

Dim csname1 As [String] = "PopupScript"
Dim cstype As Type = Me.[GetType]()
Dim cs As ClientScriptManager = Page.ClientScript

If Session("LOG") <> "OK" Then
            Session("LOG") = "ERROR"
            If Not cs.IsStartupScriptRegistered(cstype, csname1) Then
                Dim cstext1 As New StringBuilder()
                cstext1.Append("<script type=text/javascript> alert('Only members!') </")
                cstext1.Append("script>")
                cs.RegisterStartupScript(cstype, csname1, cstext1.ToString())
            End If
      Response.Redirect("Default.aspx?ID=1")
End If

I'm using master page.

My problem is that my alert never shows. But if i remove the Redirect, there is no problem?

I'm using the exact same code on many other pages without any problems? how can that be?

0
Comment
Question by:DCRAPACCESS
[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
2 Comments
 
LVL 16

Accepted Solution

by:
Swapnil Piparia earned 500 total points
ID: 34881705
Hi DCRAPACCESS,

      That's true. The reason is it register script on your current page. However before that page renders you are redirecting it to another page. So script will not get executed.

      are you doing redirect on other pages too after registering script block?
 
Thanks,
netswap
0
 

Author Comment

by:DCRAPACCESS
ID: 34881738
Hi netswap, i'm almost positive that i'm also doing the same on other pages too. But I found another way around. Instead of calling the script on the page i have troubles with, i'm using a session and then open the message from the master page instead and that works fine.

But you are 100% right about your comment about the rendering, that were the difference.

Thanks for your answer!
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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ā€¦
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Siā€¦
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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