简体   繁体   中英

Unable to access module from Default.aspx page, but can access it from Default.aspx.vb

I created a vb.net Module that outputs strings, based on some configurations in the web.config file. I can call and use the Module functions from methods and functions within the Default.aspx.vb page, but when I try to call the modules from Default.aspx like so:

<a href="<% ModuleName.GetHref() %>"><% ModuleName.GetLinkName() %></a>

I get

Error 12 'ModuleName' is not declared. It may be inaccessible due to its protection level.

The module is declared like so:

Public Module ModuleName

and all of the functions within the module are Public:

 Public Function GetHref() As String

How can I call these functions from within the .aspx page?

I would use codebehind, i don't think that you can access it directly from aspx. Therefore use the ASP.NET servercontrol HyperLink which is rendered as anchor.

Then assign it from codebehind(fe Page_Load ) via NavigateUrl and Text :

this.link.NavigateUrl = ModuleName.GetHref();
this.link.Text = ModuleName.GetLinkName();

This also has the benefit of compile time safety and is easier to debug.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM