Using Javascript from Codehind ASP.net VB

Hi,

I had this working from a content page, but as soon as I move it to a master page it has an issue with the "ClientScript" saying change ClientScript to ClientScriptManager.

The idea is to build a an item on the fly from any page its added to the basket into a literal within a Div, then the Javascript makes the DIV dropdown as a preview of the item.

        Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()
        sb.Append("<script type=""text/javascript"">")
        sb.Append("$(""#DivBasketAdd"").slideDown(1000).delay(6000).slideUp(2000);")
        sb.Append("</script>")

        If (Not ClientScript.IsStartupScriptRegistered("JSScript")) Then
            ScriptManager.RegisterStartupScript(Me, Me.GetType(), "@@@@MyPopUpScript", sb.ToString(), False)
        End If

Open in new window


Any help would be appreciated.

Cheers
Karl
Karl BlackburnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jerry MillerCommented:
I don't verify that the script was registered. According to this page the registerStartUpScript checks for duplicates before registering. The rest of your code block looks fine.

http://msdn.microsoft.com/en-us/library/fdwe5ca7(v=vs.110).aspx

"The following code example demonstrates the use of the IsStartupScriptRegistered method. Note that, if the logic to check for the existing startup script block were removed, there would not be two duplicate startup scripts in the HTML source code of the rendered page because the RegisterStartupScript method checks for duplicates. The benefit of checking is to reduce unnecessary computation."
0
Karl BlackburnAuthor Commented:
Hi,

Thats greatI got it to fire on page load, but i'm still having difficulty firing it after postback, even if I wrap it in a

If IsPostBack = True Then

It just seems to bypass it.

Cheers
Karl
0
Karl BlackburnAuthor Commented:
I know have

        Dim csname1 As String = "PopupScript"
        Dim cstype As Type = Me.GetType()
        Dim cs As ClientScriptManager = Page.ClientScript
        If (Not cs.IsStartupScriptRegistered(cstype, csname1)) Then
            Dim cstext1 As String = "$(""#DivBasketAdd"").slideDown(1000).delay(6000).slideUp(2000);"
            cs.RegisterStartupScript(cstype, csname1, cstext1, True)
        End If

Open in new window


which fires on page load from the "PreRender", but won't fire after postback. The button i'm hitting is somebody to postback and the Prerender re-fire the code, but no luck.

Cheers
Karl
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Karl BlackburnAuthor Commented:
This worked in the end

        Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()
        sb.Append("<script type=""text/javascript"">")
        sb.Append("$(""#DivBasketAdd"").slideDown(1000).delay(6000).slideUp(2000);")
        sb.Append("</script>")

        If (Not ClientScript.IsStartupScriptRegistered("JSScript")) Then
            ScriptManager.RegisterStartupScript(Me, Me.GetType(), "@@@@MyPopUpScript", sb.ToString(), False)
        End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jerry MillerCommented:
So what was your solution? That block of code that you posted is the same one in the question that I told you looked OK. At least post a solution so others can find it later whether you grant points or not.
0
Karl BlackburnAuthor Commented:
Found a solution elsewhere
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.