Solved

Problem with RegisterStartupScript

Posted on 2011-02-12
2
478 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
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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