开发者

ASP.Net - VB.Net Custom Namespace for Webpages?

I want to be able to define some namespaced constants on the code-behind of my VB.net pages.

For example,

Namespace MyCompany
    Namespace Pages

        Partial Public Class Default
            Inherits System.Web.UI.Page

            Public Const PAGE_NAME As String = "Default.aspx"

        End Class

    End Namespace
End Namespace

I want to be able to execute code like...

Response.Redirect(MyCompany.Pages.Default.PAGE_NAME)

However, the second page won't compile. The compiler error is "'Pages' is not a member of 'MyCompany'".

Any ideas. I've done the same thi开发者_如何学Gong in C# without issue, but VB.Net is giving me fits.

Thanks in advance, Jason


the main problem is u have used Default try to use _Default

this is your code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="MyCompany.Pages._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>

vb file code

Namespace MyCompany
    Namespace Pages
        Partial Class _Default
            Inherits System.Web.UI.Page

        End Class
    End Namespace
End Namespace

second file

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="MyCompany.Pages.Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <%  Response.Redirect(MyCompany.Pages.Default2.PAGE_NAME)%>
    </div>
    </form>
</body>
</html>

code for second file

Namespace MyCompany
    Namespace Pages
        Partial Class Default2
            Inherits System.Web.UI.Page
            Public Const PAGE_NAME As String = "Default.aspx"
        End Class
    End Namespace
End Namespace
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜