Using createPopup on a single button.

T

Thomasa Gregg

I have a contextmenu that I only want to show when right clicking on a
single button. I have the menu working but it happens on the entire page.
What am I doing wrong?

Thanks

Private Sub ContextMenu()

Dim ConnectionString As String =
ConfigurationSettings.AppSettings("ConnectionString")

Dim RowCount As Integer

Dim IDCount As Integer

Dim CommandText As String = "SELECT DISTINCT um.corigin AS Origin, g1.name
AS OriginName "

CommandText += "FROM tmpUnitMove um "

CommandText += "LEFT JOIN tmpUnits u ON um.uitempunitkey =
u.uitempunitkey "

CommandText += "LEFT JOIN geofile g1 ON um.corigin = g1.geo "

CommandText += "WHERE um.csessionid = '" & Session.SessionID & "' OR
um.cSaveSessionId = '" & Session.SessionID & "'"

CommandText += "ORDER BY g1.name"

Dim myConnection As New SqlConnection(ConnectionString)

Dim myCommand As New SqlDataAdapter(CommandText, myConnection)

Dim HTML As New System.Text.StringBuilder

Dim ds As New DataSet

Dim dsRow As DataRow

myCommand.Fill(ds)

RowCount = ds.Tables(0).Rows.Count

Dim NameWidth As Integer = 0

For Each dsRow In ds.Tables(0).Rows

If Len(dsRow.Item("OriginName")) > NameWidth Then

NameWidth = Len(dsRow.Item("OriginName"))

End If

Next

IDCount = 0

With HTML

.Append("<TABLE STYLE=""border:1pt solid #808080"" BGCOLOR=""#FFFFFF""
WIDTH=""")

.Append(NameWidth * 8)

.Append(""" HEIGHT=""")

.Append(RowCount * 25)

.Append(""" CELLPADDING=""0"" CELLSPACING=""1"">")

.Append("<STYLE TYPE=""Styles/css"">\n")

.Append("a:link {text-decoration:nonefont-family:Arialfont-size:8pt}\n")

.Append("a:visited
{text-decoration:nonefont-family:Arialfont-size:8pt}\n")

.Append("td {font-size:8pt}\n")

.Append("</STYLE>\n")

For Each dsRow In ds.Tables(0).Rows

.Append("<TR><TD ID=Row")

.Append(IDCount)

.Append(" STYLE=""border:1pt solid #FFFFFF""
ONMOUSEOVER=""document.all.Row")

.Append(IDCount)

.Append(".style.background=\'highlight\';document.all.Row")

.Append(IDCount)

.Append(".style.border=\'1pt solid #FFFFFF\';""
ONMOUSEOUT=""document.all.Row")

.Append(IDCount)

.Append(".style.background=\'#FFFFFF\';document.all.Row")

.Append(IDCount)

.Append(".style.border=\'1pt solid #FFFFFF\';""
ONCLICK=""window.history.go(-1);"">")

.Append(dsRow.Item("OriginName"))

.Append("</TD></TR>")

IDCount += 1

Next

.Append("</TABLE>")

End With

Dim Script As New System.Text.StringBuilder

With Script

.Append("<Script Language=JavaScript>")

.Append("var oPopup = window.createPopup();")

.Append("function dopopup(x,y) {")

.Append("var oPopupBody = oPopup.document.body;")

.Append("oPopupBody.innerHTML = '" & HTML.ToString & "';
oPopupBody.style.cursor=""hand"";")

.Append("oPopup.show(x, y, ")

.Append(NameWidth * 8)

.Append(", ")

.Append(RowCount * 25)

.Append(", document.body);")

.Append("}")

.Append("document.oncontextmenu = function() {
dopopup(event.x,event.y);return false; }")

.Append("</Script>")

End With

RegisterStartupScript("ContextMenu", Script.ToString)

End Sub
 
E

Eliyahu Goldin

Without analyzing the attached code I can guess that you are attaching the
contextmenu event handler to the document. You should do it for the button
instead.

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top