[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using Javascript from Codehind ASP.net VB

Posted on 2014-08-27
6
Medium Priority
?
170 Views
Last Modified: 2014-09-10
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
0
Comment
Question by:Karl Blackburn
  • 4
  • 2
6 Comments
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 40289186
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
 

Author Comment

by:Karl Blackburn
ID: 40289792
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
 

Author Comment

by:Karl Blackburn
ID: 40289818
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
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!

 

Accepted Solution

by:
Karl Blackburn earned 0 total points
ID: 40305577
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
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 40305757
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
 

Author Closing Comment

by:Karl Blackburn
ID: 40314010
Found a solution elsewhere
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 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