I use a repeater to create an HTML table with values ββthat come from the database. This part works fine:
TEST.ASPX: <td><%# FancyFormat(Eval("MyColumnName"))%></td>
The function I use is defined in my code:
TEST.ASPX.VB: Function FancyFormat(ByVal Whatever As String) As String
This is just a date formatting function, a very common bit of code.
So, I decided to create a better function in the class file in the same project, because I want to use this function on twenty other web pages:
HELPFUL.VB: Public Shared Function BeautifulFormat(ByVal Whatever As String) As String
Blissfully ignorant, I type the following:
TEST.ASPX: <td><%# Helpful.BeautifulFormat(Eval("MyColumnName"))%></td>
Unfortunately, I get the error message "Itβs not usefully announced, it may not be available due to its level of protection."
I read a similar asp.net question . Can a public function from another class be called in a repeater? but these decisions speak of inheritance. It seems inappropriate to abuse inheritance for things like date formatting. Such a function is very "global", and you want to use it in many different places of the project, and not just on web pages. What if you need it in a web service or in GLOBAL.ASAX.VB?
So my question is: can you make an accessible function the way I want without using inheritance? Or do I need to settle for Public Class Helpful Inherits System.Web.UI.Pageand modify my code files to have Inherits Helpfulin them?
source
share