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)
        sqlConnInsert.Open()

        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")))
        addcommand.ExecuteNonQuery()

        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

John0214Asked:
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!
0
 
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
http://www.singingeels.com/Articles/Using_Page_Methods_in_ASPNET_AJAX.aspx
0
 
Kamal KhaleefaInformation Security SpecialistCommented:
if you want just after completing your code
add response.redirect(demos/mydemo.htm")
0
 
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.
0
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.