Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Register client script

Status
Not open for further replies.

TheCivic

Programmer
Feb 7, 2006
34
GB
Hi everyone,

I am trying to register this client script but for some reason i cant access Page.ClientScript

This is my code, it takes a datatable in and formats the data that i want. My concern is to find out how to get the javascript to register on the page

Any help would be apprieciated.

Imports Microsoft.VisualBasic

Public Class ViewDataForObject

Shared Function FormatViewableDataInTable(ByVal oDT As Data.DataTable) As Table

Dim i As Integer

Dim oDR As Data.DataRow

Dim SingularUserName As String

Dim FieldValue As String

Dim TypeOfLink As String

Dim ValueForLink As String

Dim cLabel As HyperLink

Dim cData As Label

Dim TableWithData As New Table

TableWithData.CellPadding = 1

TableWithData.CellSpacing = 0

TableWithData.Width = Unit.Percentage(100)

For i = 0 To oDT.Rows.Count - 1

oDR = oDT.Rows.Item(i)

SingularUserName = oDR.Item("SingularUserName").ToString

FieldValue = oDR.Item("FieldValue").ToString

If Not oDR.Item("TypeOfLink") Is DBNull.Value Then

TypeOfLink = oDR.Item("TypeOfLink").ToString

ValueForLink = oDR.Item("ValueForLink").ToString

Else

TypeOfLink = String.Empty

ValueForLink = String.Empty

End If

cLabel = FormatLabel(SingularUserName, TypeOfLink, ValueForLink)

cData = FormatData(FieldValue)

Next

Return TableWithData

End Function

Shared Function FormatLabel(ByVal ScreenName As String, ByVal TypeOfLink As String, ByVal LinkData As String) As HyperLink

Dim uLabel As New HyperLink

uLabel.Text = ScreenName

If Not TypeOfLink = String.Empty Then

uLabel.Style.Add("font-weight", "bold")

Select Case TypeOfLink

Case "CLIPBOARD"

Dim jsScript As String

Dim oAddress As New HiddenField

LinkData = Replace(LinkData, "|", vbCrLf)

oAddress.ID = "sysCopyAddress"

oAddress.Value = LinkData

jsScript = "<script language=""Javascript"">"

jsScript += "function CopyAddress() { "

jsScript += "lbl = document.getElementById(" & oAddress.ClientID & ").createTextRange();"

jsScript += "lbl.execCommand(""Copy""); "

jsScript += "alert('The address has been copied to your clipboard'); } </script>"

uLabel.Controls.Add(oAddress)

Dim clientScript as clientscriptmanager = page.clientscript ' CANT GET REFERENCE HERE TO PAGE.CLIENTSCRIPT

If Not (clientScript.IsClientScriptBlockRegistered("CopyAddress")) Then

clientScript.RegisterClientScriptBlock(GetType(), "CopyAddress", jsScript)

End If

End If

Return uLabel

End Function

Shared Function FormatData(ByVal Val As String) As Label

Dim uLabel As New Label

uLabel.Text = Val & " "

uLabel.Style.Add("font-family", "Verdana")

uLabel.Style.Add("font-size", "X-Small")

Return uLabel

End Function

End Class

End Namespace
 
A class has no concept of what the "page" is? How could it? If you want to access the page itself, you'll have to pass it to the class, modify it and then return it.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I call this class method from my page, any ideas on how to get it to work? or a possible work around?
 
Yes, wither use the method I suggested above or set the javascript to a public variable and on the page register the javascript using that variable.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I have made a reference to the page that i am loading on to, but now the control is being added to the page, but outside of the form tag. any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top