What happens if the Inherits attribute is removed from the #Page directive? - asp.net

I don't know what happened with my project, but since I reinstalled my pc with Windows 8, the website doesn't build...
My #Page directives look summing like this:
<%# Page Title="Register" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
CodeBehind="Register.aspx.vb" Inherits="_Register" %>
The codebehind for this page looks like this:
Partial Class _Register
Inherits MobilePage
' subs go here (don't think they're important for the question)
End Class
With this set up this way, I'm getting the following error:
Could not load type '_Register'.
Removing the Inherits attribute fixes this error, but what else does it do in terms of the page's functionality?

Related

Context is not a member of MyProg._Default

I am endeavouring to correct a problem with a Web Project:-
Could not load type 'MyProg._Default'.
To fix this I have adopted the solution suggested here and changed CodeBehind into CodeFile. As is customary in ASP.Net Whack-a-Mole, this has introduced a new and different error:-
Context is not a member of 'MyProg._Default'
The very strange solution to this suggested here doesn't seem likely to fix the problem as I have no user-defined controls on the form.
I have two questions, really. First, is changing CodeBehind this way likely to fix the original problem, and if so how do I fix the new problem?
Edit to answer wazz's question, the top line in the aspx is:-
<%# Language="VB"
AutoEventWireup="true"
Inherits="MyProg._Default"
CodeFile="Default.aspx.vb"
MaintainScrollPositionOnPostback="true" %>
and the class is defined thus:-
Public Class _Default
Inherits System.Web.UI.Page

Could not load type error in application page

I have created a application page for login functionality in sharepoint by following this post.
But this giving me an error at inheriting the page. I have folder structure and .aspx file like below.
Did I done any mistake while giving the link to the .cs file in the application page?
After I deployed into my site, it is giving me error like below.
I am trying to resolve it from 2 hrs, but unable to find the solution. Can any one suggest me the way to do it please!!
Try to add
<%# Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
before
<%# Page ... %>
Add $SharePoint.Project.AssemblyFullName$ to your Inherits attribute
Instead of <%# Page Language="C#" AutoEventWireup="true" CodeBehind="YourPage.aspx.cs" Inherits="YourNamespace.YourPage" %>
Use <%# Page Language="C#" AutoEventWireup="true" CodeBehind="YourPage.aspx.cs" Inherits="YourNamespace.YourPage,$SharePoint.Project.AssemblyFullName$" %>
This could also be happened when there are another reference to that assembly which didn't exist. To show the error, simply check Ha Doan answer.

could not create type XYZ.ashx

When I am trying to build my solution I am getting Could not create type Upload.ashx.I am pulling out my hair to solve this.Can anyone suggest me how to rectify this problem.And I don't know how to actually append the namespace to the class?
As I am having
Here is my code:
<%# WebHandler Language="vb" CodeBehind="Upload.ashx.vb" Class="Upload" %>
And this is my dir structure:
wwwroot/Test/Myproject
I don't think there is such a thing as an .ashx.vb file type.
Try changing your top line to:
<%# WebHandler Language="VB" Class="Upload" %>
and then just put your code behind code in the .ashx file
<%# WebHandler Language="VB" Class="Upload" %>
Imports System
Imports System.Web
Public Class Upload : Implements IHttpHandler
'Code here....
End Class
Alternatively, have you tried building your code?
See this similar question for more help:
Custom Http Handlers IIS7 and ASP.NET
I've been banging my head against the wall for a few hours over this error "could not create type", and it may not help your exact problem
I had split my codebehind across many partial classes, all called "restserver" apart from one which was called "restServer" (note the capital S) it was that small difference that was causing the error, I changed them all to the same case and it worked perfectly.
VS isn't very helpful when working with ASHX files.
I know this is an old question, but it is at the top of google at the moment, so for anyone looking: In a website project, the handler directive expects different parameters for websites and webapps. In this case (website) was looking for codeFile instead of (webapp) codeBehind:
<%# WebHandler Language="vb" CodeFile="Upload.ashx.vb" Class="Upload" %>
Add below tag
<%# Assembly Name="YourNameSpace.YourHandlerClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=90e3045b123af1c3" %>
above your WebHandler tag
<%# WebHandler Language="vb" CodeBehind="Upload.ashx.vb" Class="Upload" %>
Necromancing a thread but I just had the same issue. The suggestion for Assembly Name by #sagar-s didn't work for me. So I tried this and I got a good build (not sure yet about actual functionality) :
<%# Assembly Src="~/MyService.ashx.cs" %>
<%# WebHandler Language="C#" CodeBehind="MyService.ashx.cs" Class="Namespace.MyService" %>
The Src and Name attributes are mutually exclusive. The CodeBehind attribute and Src attribute are redundant. I haven't tried to see if Src will be adequate if CodeBehind is removed. No time to experiment at almost 3am here - or to read docs which may clarify such things. HTH

How to add code behind manually on asp.net

I have a website on the IIS but it has only the aspx file. Now I need to add the code behind for some pages. How do I go about this?
I've been trying to add the attribute "codebehind" and "autoeventwireup" on the top of the aspx file but no luck (the page_load event is not being called). Also, if I double click on the button from the design view in Visual Studio, it creates the javascript handle (not the server code).
In your page directive on the aspx page (<%# Page...), you need two pieces:
1) CodeFile="Default.aspx.vb"
2) Inherits="_Default"
In your code-behind file, you need two things:
1) The file name has to be whatever you specified above (CodeFile = "...)
2) the class name has to be whatever you specified above (Inherits="_...)
For example, if your aspx page was named "default.aspx" then your page direction in the aspx page would look similar to this:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
And your code-behind would look similar to this:
Partial Class _Default
Inherits System.Web.UI.Page
End Class
you want the #page directive and the class attribute. MSDN docs here

Creating a Template Item from a web form and auto generating the Inherits page directive

OK, so I'm trying to create a template item from a web form.
I have referenced this article: http://www.west-wind.com/weblog/posts/740022.aspx
and it exports the template and installs it fine.
When you try and use the template item within a project though it leaves the inherits="_Default" in the page directive like shown below:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="FormTemplateDev.aspx.cs" Inherits="_Default" %>
So it thinks all the new template items use the original form name pre-template generation. This is an issue in the code behind too as shown here:
public partial class _Default : System.Web.UI.Page
I have seen example of passing paramater strings through but havent managed to get anything to compile. I found something like below:
public partial class $safeitemname$ : System.Web.UI.Page
Does anyone have any suggestions?
This was the link to the list of available template parameters i found:
Project Template Parameters
OK so It is as simple as this:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="FormTemplateDev.aspx.cs" Inherits="$safeitemname$" %>
and...
public partial class $safeitemname$ : System.Web.UI.Page
It threw me because the page won't compile and the page turns red with rage! This means you will have to put these $slightlystrangeparameters$ in once you have got your template item completed and built. Add the parameters in and export it as a template.
Hope this helps someone else...

Resources