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 thing 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
Related
I have a very unusual problem and would appreciate help. I have a web application in VS 2019.
I am trying to create a page that runs in its own namespace so I can share it with other websites. Below is a simple sample page and code.
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="test1.aspx.vb" Inherits="xxxx.test1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<%= Myfunc1() %>
</div>
</form>
</body>
</html>
Namespace xxxx
Public Class test1
Inherits System.Web.UI.Page
Public Function Myfunc1() As String
Myfunc1 = "Hello"
End Function
End Class
End Namespace
The compilation shows <%= Myfunc1() %> as MyFunc1 not found.
If I remove the "Namespace xxxx" from the code behind and change the Inherits="xxxx.test1" to Inherits "TestWebsite.test1" (TestWebsite is the namespace for the web project and the default setting when you add the test page). This code compiles and works OK.
I would appreciate advice on how I can achive my aim of making the namespace for the page independent of the website project.
Thanks
Paul
I'm getting an ASP Error, according to Resharper, "Solution MembersOrderEntry.sln
Project MembersOrderEntry
MembersOrderEntry\segovias-abq\Default.aspx:1 Cannot resolve symbol 'segovias-abq'"
In the same Default.aspx file, there is a similar error, "Solution MembersOrderEntry.sln
Project MembersOrderEntry
MembersOrderEntry\segovias-abq\Default.aspx:1 Cannot resolve symbol '_Default'"
Why are these symbols ('segovias-abq' and '_Default') unresolvable? The project contains many files named Default.aspx, with Default.aspx.vb beneath them; most of them throw no errors. But after letting Resharper "fix" funky namespace (where it thought they were wrong), I'm getting four of these errors.
Why are the lion's share of the Default.aspx files able to resolve their parent file, but this one is not? As you can see here, the relationship between the failing one and others are the same (a folder name, with Default.aspx beneath that, and Default.aspx.vb beneath that):
Seashore, SimonLeeman, Stern, Weyand, and many others all work fine.
The entire contents of the failing Default.aspx is:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="segovias-abq._Default" title="Web Order Entry" %>
<!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>Order Entry Login Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
...and the Default.aspx.vb for it is:
Partial Class _Default
Inherits Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Session("SelectedMenu") = "Home"
Response.Redirect("../Login.aspx?MemberNo=B1212")
End Sub
End Class
OTOH, the entire contents of one of the non-failing Default.aspx is:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Weyand._Default" title="Web Order Entry" %>
<!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>Order Entry Login Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
...and its Default.aspx.vb is:
Namespace Weyand
Partial Class _Default
Inherits Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Session("SelectedMenu") = "Home"
Response.Redirect("../Login.aspx?MemberNo=031")
End Sub
End Class
End NameSpace
IOW, except for the namespaces, they seem to be identical. But even when I added what would seem to be the one expected:
Namespace segovias-abq
...it changed nothing; I still get, "Cannot resolve symbol 'segovias-abq'"
ReSharper removes hyphens or underscores from namespaces when making the namespace names match their directory paths. During a refactoring, ReSharper will not look at string references unless you allow it.
I believe when you refactored, the hyphen was removed form the segovias-abq namespace but that namespace change does not appear to have been corrected in this portion of Default.aspx:
Inherits="segovias-abq._Default"
I am a c# guy but I need to get a small vb.net test harness working. For the life of me I can't get this to work, and can't discover why. Here's the aspx:
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="_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 id="Head1" runat="server">
<title>Source Page</title>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
</html>
And here is the .vb:
Public Class _Default
Inherits System.Web.UI.Page
End Class
Always the error "Could not load type '_Default'." I even turned the folder into a true Application in IIS but it made no difference. What am I missing?
What am I missing?
Try the below two -
If your code-behind contains a namespace then modify your inherits attribute in Page directive as Inherits="namespace._Default".
If it doesn't, simply remove this Inherits attribute from Page Directive.
Changing the Codebehind attributename to CodeFile worked for me:
vb
CodeFile="Default.aspx.vb"
C#
CodeFile="Default.aspx.cs"
I have a aspx page that begins like this:
<%# Page Language="C#" MasterPageFile="~/Main_MP_Teacher.master" AutoEventWireup="true" CodeFile="default.aspx.cs"
Inherits="Teacher_default" Title="Teacher Page" %>
I want to include html in this page also but when I put in the first line
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
I get a parse error. What am I doing wrong?
The parser error is probably because you're putting something other than <asp:ContentPlaceHolder> in the root of your ASPX page.
If you're using a MasterPageFile then the <!DOCTYPE should be at the start of the MasterPage.
This is unless you have a <asp:ContentPlaceHolder> right at the start of the MasterPage, which you can put the <!DOCTYPE into it.
MORE INFORMATION
The <!DOCTYPE should always be the very first thing in the HTML file, so normally your MasterPage would look something like this...
<%# Master Language="VB" CodeBehind="MyMaster.master.vb" Inherits="dev.MyMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
<html>
<head>
<asp:ContentPlaceHolder runat="server" id="myHeader"/>
</head>
<body>
<form id="form1" runat="server">
<asp:ContentPlaceHolder runat="server" id="myBody"/>
</form>
</body>
</html>
If for some reason you wanted to have a page specified doc type, then you could add a new placeholder at the start, with a default value...
<%# Master Language="VB" CodeBehind="MyMaster.master.vb" Inherits="dev.MyMaster" %>
<asp:ContentPlaceHolder runat="server" id="myDocType">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
</asp:ContentPlaceHolder>
<html>
...
</html>
And then in the page you want to override put the following (by NOT overriding, the original will be output instead)...
<%# Page Language="vb" MasterPageFile="MyMaster.master" Codebehind="MyPage.aspx.vb"
Inherits="dev.MyPage" Title="My Page" %>
<asp:Content runat="server" ContentPlaceHolderId="myDocType">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
</asp:Content>
...
I call flush but the page just hangs for 5second (purposely) then renders completely. Why isnt it showing me the first part then the last?
Firefox 7 and chrome both do this
code file
using System;
namespace ABC
{
public class Test
{
static public void Apple()
{
System.Web.HttpContext.Current.Response.Flush();
System.Threading.Thread.Sleep(5000);
}
}
}
page
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._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>
hi
<form id="form1" runat="server">
<div>
starting
<% ABC.Test.Apple(); %>
<% WebApplication1._Default.RecurseMe(Response, #"/var/www/wordpress", 0); %>
</div>
</form>
</body>
</html>
I don't think a web browser will show the page before it's done loading the HTML. Think about it this way.. there are tags that need to be closed before the page can be rendered correctly and is a tag.
I'm not sure why you need to do this, but if you want to hide some data while it loads you should hide the area in a hidden div and then display it using javascript after the time interval or some other method such as an AJAX callback.