How to call functions in a class file when inside a repeater, without inheritance

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?

0
source share
2 answers

?

<td><%# [ProjectName].Helpful.BeautifulFormat(Eval("MyColumnName"))%></td>

?

, .

+1

Public Shared

Public Shared Function BeautifulFormat(ByVal Whatever As String) As String

End Function
0

Source: https://habr.com/ru/post/1723651/


All Articles