[英]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. 我创建了一个vb.net模块,该模块基于web.config文件中的某些配置输出字符串。 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:
我可以从Default.aspx.vb页面中的方法和函数调用和使用Module函数,但是当我尝试从Default.aspx调用模块时,如下所示:
<a href="<% ModuleName.GetHref() %>"><% ModuleName.GetLinkName() %></a>
I get 我懂了
Error 12 'ModuleName' is not declared.
错误12'ModuleName'未声明。 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:
Public Function GetHref() As String
How can I call these functions from within the .aspx page? 如何在.aspx页中调用这些函数?
I would use codebehind, i don't think that you can access it directly from aspx. 我会使用代码隐藏,我不认为您可以直接从aspx访问它。 Therefore use the ASP.NET servercontrol
HyperLink
which is rendered as anchor. 因此,请使用呈现为锚点的ASP.NET服务器控件
HyperLink
。
Then assign it from codebehind(fe Page_Load
) via NavigateUrl
and Text
: 然后通过
NavigateUrl
和Text
从codebehind(fe Page_Load
)中分配它:
this.link.NavigateUrl = ModuleName.GetHref();
this.link.Text = ModuleName.GetLinkName();
This also has the benefit of compile time safety and is easier to debug. 这还具有编译时安全性且易于调试的优点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.