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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sub which uses Page class not recognized

Status
Not open for further replies.

JSMITH242B

Programmer
Mar 7, 2003
352
GB
Hi Group
I have the following sub which I would like to share because the code will be used by a number of my webforms.
Public Sub MonitorChanges(ByVal wc As WebControl)
If wc Is Nothing Then Exit Sub
'check boxes and radio boxes are treated
'differently in asp.NET need to
'client id is the Server Control ID generated by ASP.NET

If TypeOf wc Is CheckBoxList OrElse TypeOf wc Is RadioButtonList Then
'Add an array element for each item
For i As Integer = 0 To CType(wc, ListControl).Items.Count - 1

Page.RegisterArrayDeclaration("monitorChangesIDs", """" & _
String.Concat(wc.ClientID, "_", i) & """")
Page.RegisterArrayDeclaration("monitorChangesValues", "null")
Next
Else
Page.RegisterArrayDeclaration("monitorChangesIDs", _
"""" & wc.ClientID & """")
Page.RegisterArrayDeclaration("monitorChangesValues", "null")

AssignChangeValuesOnPageLoad()
End If
End Sub

As soon as I put shared in, I get a squiggly line under the Page directive. Why is this so?


Here is the AssignChangeValuesOnPageLoad() sub routine too which is affected too.
Private Sub AssignChangeValuesOnPageLoad()

If Not Page.IsStartupScriptRegistered("monitorChangesAssignment") Then
Page.RegisterStartupScript("monitorChangesAssignment", _
"<script language = ""Javascript"">" & vbCrLf & _
"assignInitialValuesForMonitorChanges();" & vbCrLf & _
"</script>")
Page.RegisterClientScriptBlock("monitorChangesAssignmentFunction", _
"<script language = ""Javascript"">" & vbCrLf & _
"function assignInitialValuesForMonitorChanges() {" & vbCrLf & _
"for (var i = 0; i < monitorChangesIDs.length; i++) {" & vbCrLf & _
"var elem = document.getElementById(monitorChangesIDs);" & vbCrLf & _
"if (elem) if (elem.type =='checkbox' ||elem.type == 'radio') " & _
"monitorChangesValues = elem.checked; " & _
"else monitorChangesValues = elem.value;" & vbCrLf & _
" }" & vbCrLf & _
" }" & vbCrLf & vbCrLf & vbCrLf & _
" var needtoConfirm= true;" & vbCrLf & _
" window.onbeforeunload = confirmClose;" & vbCrLf & _
" function confirmClose() {" & vbCrLf & _
" if(!needtoConfirm) return;" & vbCrLf & _
" for (var i = 0; i < monitorChangesValues.length; i++) {" & vbCrLf & _
" var elem = document.getElementById(monitorChangesIDs);" & vbCrLf & _
" if (elem) if (((elem.type == 'checkbox' || elem.type == 'radio') && elem.checked != monitorChangesValues) || (elem.type != 'checkbox' && elem.type != 'radio'&& elem.value !=monitorChangesValues)) {needtoConfirm = false; setTimeout('resetFlag()', 750); return ""You have made changes to the data but have not saved it. If you leave this page, any changes will be lost. To save changes, click on the cancel to return to the page and click on the Save button to save the data."";}" & vbCrLf & _
" } " & vbCrLf & _
" }" & vbCrLf & vbCrLf & _
" function resetFlag(){needtoConfirm = true;} " & vbCrLf & _
" </script>")

End If
End Sub

If you copy the above code as is and put into a vb class and change them to shared routines, you will see what I mean.

Kind Regards
 
and what does the error say???

Known is handfull, Unknown is worldfull
 
If you change the MonitorChanges sub to a shared sub do you get a squiggly line under the Page class?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top