This function works perfectly in my code behind page but I need to access this function globally.. So I move it to the app_code folder. Now, I am a bit lost on how to declare my label ID in a way that my new app_code File function finds it.
my error message = Error 35 'Label1' is not declared. It may be inaccessible due to its protection level. note: i do not not get this error in my code behind file
Thnx
Namespace BranchHours Public Class branchHours
' Public Shared Property Label1 As Object
Public Shared Function MyFunc(ByVal branchCode As String) As String
Dim URLString As String = "url/branchesTesting.xml"
Dim xmlDoc As XDocument = XDocument.Load(URLString)
' Dim root As XmlNode = xmlDoc.DocumentElement
' Dim hoursList As XmlNodeList = root.SelectNodes("/BranchesInfo/BranchInfo[BranchId='db']/BranchHours/Hours")
Dim x As Integer = 0 'looping variable
Dim branchid = xmlDoc.XPathSelectElements("/BranchesInfo/BranchInfo[BranchId='" & branchCode & "']/BranchHours/Hours")
Dim branchname = xmlDoc.XPathSelectElements("/BranchesInfo/BranchInfo[BranchId='" & branchCode & "'/Name]/BranchHours/Hours")
Dim Items = From BranchHours In xmlDoc.XPathSelectElements("/BranchesInfo/BranchInfo[BranchId='" & branchCode & "']/BranchHours/Hours") _
Select DayOfWeek = BranchHours.Element("DayOfWeek").Value, Open = BranchHours.Element("Open").Value, _
Close = BranchHours.Element("Close").Value
Label1.Text = ""
For Each Hours In Items
' If x = 0 Then
' Label1.Text = Label1.Text & "<div>DayOfWeek:" & Hours.DayOfWeek & "</div>" + vbLf
Label1.Text = Label1.Text & "<div>DayOfWeek:" & Hours.DayOfWeek & "</div>" + vbLf
Label1.Text = Label1.Text & "Open: " & Hours.Open + vbLf
Label1.Text = Label1.Text & "Close: " & Hours.Close + vbLf
' Else
' x = x + 1
' End If
Next
If Label1.Text = "" Then
Label1.Text = "No Results."
End If
Return Label1.Text
End Function
End Class
End Namespace
Public Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Call BranchHours.branchHours.MyFunc("dr")
Label1.Text = BranchHours.branchHours.MyFunc("dr")
End Sub
<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="Default3bh.aspx.vb" Inherits="Default3bh" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:Label ID="Label1" runat="server" For="label1"></asp:Label>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="AdditionalContent" Runat="Server">
</asp:Content>
Answered in comments by Chetan Ranpariya
Instead of using Label1 in the method you should create a string variable and return it from the method – Chetan Ranpariya