Insert record in database and open Highslide javascript pop-up with one click.

Hi, experts - I am in need of your assistance.

My scenario is this: We offer training videos that authorized users can view on our website. When a user clicks a link to a video, we want to capture that click (along with some session info) in a database table so we know it was clicked on, and also display the video within a Highslide javascript pop-up window.

So far I've been able to do either or, but not together. I've tried LinkButtons, Hyperlinks, and Buttons. I'm hoping that this is possible and that I just plain don't know the syntax involved.

Below is the code I used for my LinkButton. In this example, clicking the LinkButton does insert into the database and the Highslide window tries to open, but just sits on the "Loading" graphic and never loads. Does anything glaring look amiss? Is there a better way to do this?

Thanks for any help you might provide.
Protected Sub LinkButton1_Click(sender As Object, e As System.EventArgs) Handles LinkButton1.Click
        Dim ConSql As String = ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString
        Dim ConIns As String = "INSERT INTO DemosClicked (txtEntryCode, txtRequestor, txtModuleClicked) VALUES (@ec, @req, @c)"
        Dim sqlConnInsert As SqlConnection
        sqlConnInsert = New SqlConnection(ConSql)

        Dim addcommand As New SqlCommand(ConIns, sqlConnInsert)
        addcommand.Parameters.Add(New SqlParameter("@ec", Session("EntryCodeVar")))
        addcommand.Parameters.Add(New SqlParameter("@req", Session("RequestorVar")))
        addcommand.Parameters.Add(New SqlParameter("@c", Session("RequestorVar")))

        LinkButton1.Attributes.Add("postbackurl", "/demos/mydemo.htm")
        LinkButton1.Attributes.Add("onclick", "return hs.htmlExpand(this, {objectType:  'iframe', width: '640' } )")
    End Sub

Open in new window

Who is Participating?
John0214Connect With a Mentor Author Commented:
Thank you both for your comments/suggestions. I decided on a different approach. Instead of wiring the two events to one LinkButton (which I wasn't having success doing), I opted to change the LinkButton to a regular hyperlink that opens the Highslide window, then do the database insert on the Highslide pop-up window's Page Load.

Thanks again!
Bob LearnedCommented:
That is starting to sound like a disconnect caused by the post-back for the LinkButton click, and the client-side JavaScript component.  It is interesting that you are adding attributes for every LinkButton click.  You might want to think about a different approach, such as calling server-side code from a JavaScript (AJAX page method).

Using Page Methods in ASP.NET AJAX
Kamal KhaleefaInformation Security SpecialistCommented:
if you want just after completing your code
add response.redirect(demos/mydemo.htm")
John0214Author Commented:
Good suggestions from experts, but the resolution of the original question was not achieved. Instead, I got the desired result by changing the way the application worked. Thanks.
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.

All Courses

From novice to tech pro — start learning today.