Again, I'm fairly new at this sort of thing and perhaps the error message is telling me what it is and I'm simply not understanding, but... This code in anon.cs
namespace cheese.pies.org
{
using System;
using System.IO;
using System.Net;
using System.Web;
using System.Xml;
public class CasLogin : System.Web.UI.Page
{
private const string CasHost = "notimportant";
public static string GetId()
{
}
}
Ends up giving me an error when referenced here:
<% #Page Language="C#" Inherits="CasLogin" CodeFile="CasLogin.cs" %>
<script language="C#" runat="server">
protected void Page_Load(object sender, EventArgs e) {
String directoryId = CasLogin.GetId();
FormsAuthentication.RedirectFromLoginPage(directoryId, false);
}
</script>
The error is on line one and is:
Compiler Error Message: ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
If I change it from
public class CasLogin : System.Web.UI.Page
to
public class CasLogin : Page
I get this error:
Compiler Error Message: CS0246: The type or namespace name 'Page' could not be found (are you missing a using directive or an assembly reference?)
If I change it from public class CasLogin : System.Web.UI.Page to
public class CasLogin : Page I get this error
You are missing the correct using statement for the Page class (System.Web.UI) thus when you remove the full qualification the compiler can no longer find the Page class.
You should also fully-qualify the class name in the Page directive, i.e. Inherits="cheese.pies.org.CasLogin"
Good
<% #Page Language="C#" Inherits="cheese.pies.org.CasLogin" CodeFile="CasLogin.cs" %>
Bad
<% #Page Language="C#" Inherits="CasLogin" CodeFile="CasLogin.cs" %>
Per your comment regarding a missing partial modifier:
public class CasLogin : System.Web.UI.Page
Should be:
public partial class CasLogin : System.Web.UI.Page
This tells the compiler that the CasLogin class is defined in multiple files (which is the case with web forms; the designer file is separate from the code behind file).
If it still doesn't work, I suggest recreating the page and copying any relevant code into it. Normally Visual Studio handles all of this automatically and this is a non-issue.
I'm pretty sure it should be
<% #Page Language="C#" Inherits="cheese.pies.org.CasLogin" CodeFile="CasLogin.cs" %>
For the other error you can use
using System.Web.UI;
public class CasLogin : Page
Without fully qualifying the class name it doesn't know which Page you're talking about, so you can be explicit when you declare the class or you can use a using statement. The first error is the same issue, it can't see the CasLogin class inside the chees.pies.org namespace
inherits needs to be:
Inherits="cheese.pies.org.CasLogin"
Looking at my own little test project/code, I see a few things noticably different: the "usings" come before the namespace declaration, and the use of partial class for code behind. Also, note that the Inherits has the fully qualified class (includes namespace).
in Default.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
in Default.aspx.cs
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
using System.Data;
namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{
Related
So I need to develop a web form to get data from the scanner. But I encounter a problem stating that " "is not allowed here because it does not extend class 'System.Web.UI.Page'.
As I'm aware that this topic is already been discussed, I still not able to solve it.
I have tried this steps but none of this working..
Webform not allowed because it does not extend Class
Parser Error: '_Default' is not allowed here because it does not extend class 'System.Web.UI.Page' & MasterType declaration
Webform not allowed because it does not extend Class
and already skim thorugh this https://weblog.west-wind.com/posts/2005/Sep/12/Understanding-Page-Inheritance-in-ASPNET-20 to understand more about the inheritance.
this is the lalala.aspx file
<%# Page Language="C" AutoEventWireup="true" CodeBehind="lalala.aspx.cs" Inherits="TEST.lalala" %>
this is the lalala.aspx.cs file
namespace TEST
{
public partial class lalala : Form
{
//
}
}
I really think that this error is cause by the page inheritance but I don't know how to fix it.. Please someone guide me
Try this (presuming you are not using a master page):
namespace TEST
{
public partial class lalala : System.Web.UI.Page
{
}
}
I have this control:
public partial class controls_UploadedImageView : System.Web.UI.UserControl
{
And in a static function I have this code:
using (var ctl = (controls_UploadedImageView)tmp0.LoadControl("~/controls/UploadedImageView.ascx"))
{
ctl.RenderControl(h);
}
However the cast to `` fails:
The type or namespace name 'controls_UploadedImageView' could not be
found (are you missing a using directive or an assembly reference?)
I can't work out how to cast the control properly so I can set it's properties before rendering.
Update
Turns out that as my project is a website project and not a Web Application, it is causing this issue. A solution is to convert the entire project to a web application but this looks time consuming and fiddly. Does anyone have any solution that doesn't require me to convert the entire project?
I think I have fixed this before by using an interface.
Create an interface in the app_code folder
public interface ICustomControl
{
... add any extra methods here
}
when you declare the class for your user control, include that interface
public partial class controls_UploadedImageView : System.Web.UI.UserControl, ICustomControl
then use that interface.
using (var ctl = (ICustomControl)tmp0.LoadControl("~/controls/UploadedImageView.ascx"))
This is all from memory, but hopefully it gets you close to the solution. I'll check my code later if its not helping.
Try simply adding a namespace to your .ascx.cs (may need to update the .ascx also). Then add a using <namespace>; statement to the class that needs to reference that control.
Ex:
namespace MyFancyNamespace
{
public partial class controls_UploadedImageView : System.Web.UI.UserControl
{
}
}
and...
using MyFancyNamespace; //this goes at the top of your class.
using (var ctl = (controls_UploadedImageView)tmp0.LoadControl("~/controls/UploadedImageView.ascx"))
{
ctl.RenderControl(h);
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PageProcessingDemo
{
public partial class : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
i haven't done anything yet ,but it still showing " Identifier expected ",and pointing to ":" when double clicked.
You haven't specified class name.
Change your code to something like this:
public partial class MyPageClass : System.Web.UI.Page
P.S: Also, you have said that:
i haven't done anything yet
I am pretty sure that somebody has removed name of the class.
Additional details:
Try to add new WebForm to the project. Set the name of form to WebForm1.After clicking OK, VisualStudio will create three or two files depending on the type of the project:
WebForm1.aspx
WebForm1.aspx.cs
WebForm1.aspx.designer.cs (WebApplication project)
The *.aspx files are the markup and the *.aspx.cs files are the code-behind files. Code-behind files handle the .NET code for any server-side controls in the *.aspx files. And Asp.Net will generate your code behind files as partial classes like that:
public partial class WebForm1 : System.Web.UI.Page
Opening a page in Enterprise Portal results in an error shown in Windows-Event-Log:
MyControl.ascx.cs(15): error ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
Line 15 is marked with (X) in the source below.
ASCX.CS file:
namespace Company.Productgroup
{
(X) public partial class Productname : System.Web.UI.UserControl
{
...
}
}
ASCX file:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Productname.ascx.cs" Inherits="Company.Productgroup.Productname" %>
ASCX.designer.cs file:
namespace Company.Productgroup {
public partial class Productname : System.Web.UI.UserControl
{
...
}
}
What I tried:
Changing the atribute CodeBehind to CodeFile and vice versa
Removing Namespace from ASCX.cs Removing Namespace from
ASCX.designer.cs Changing Inherits attribute in ASCX file to
Productname / Productgroup.Productname
Searched Google / SO for a solution. In nearly every result, the
problem was a non-match between Inherit-attribute and
namepace/classname, eg: Link1, Link2, Link3
What is fact:
All files are stored in the same directory, so no paths-problems
should occur.
Default namespace in VS project is set to Company.Productgroup
Your designer file seems to be the problem. In it the class name is Product while in the other two files it is Productname. It's a little odd that it would be out of sync because the designer file is generated but I have seen it happen. Try fixing it manually and see what happens.
UPDATE
Based on your comments I decided to take a look at some of our ASCXs to see what might be different. In none of ours did the designer file show the inheritance chain. For example:
AutoHideField.ascx.cs
namespace Foo
{
public partial class AutoHideField : System.Web.UI.UserControl
AutoHideField.ascx.designer.cs
namespace Foo
{
public partial class AutoHideField
AutoHideField.ascx
<%# Control ... Inherits="Foo.AutoHideField" %>
I have been trying to figure this out for a while now and even though there are plenty of Google results for the error message I receive the solution eludes me. I think that I am doing what I am supposed to be doing.
VS2010, I created a common.cs in App_Data. The content of common.cs are functions which will be used by all pages. As far as I can tell this is the proper way to share code-behind code among multiple pages.
App_Data\common.cs
namespace nprah
{
public class BasePage : System.Web.UI.Page
{
}
{
fish-creek.aspx.cs
namespace nprah
{
public partial class Fishck : BasePage
{
}
}
fish-creek.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeFile="fish-creek.aspx.cs" Inherits="nprah.BasePage" %>
If I understand the Inherits attribute correctly then it does need to contain the NameSpace.ClassName, which mine does. See: http://support.microsoft.com/kb/312311
When I run this code it results in the following output:
Compiler Error Message: ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
Source Error:
Line 11: {
Line 12:
Line 13: public partial class Fishck : BasePage
Line 14: {
Line 15:
Visual Studio is not showing any errors during the design. Any guidance you may be able to provide will be much appreciated. Thanks in advance.
In your ASPX it should be
Inherits="nprah.Fishck"
Inherits in your .aspx should be mapping to your code file(.cs)... and from there your codefile will inherit your basepage like you already did.
And also try to validate that : CodeFile="fish-creek.aspx.cs".
Because with the name of the file you supplied it should be : Codefile="fishck.aspx.cs".
Maybe just a typo.