Single ASPX page - No code behind - Page Directive - c#

I have a single aspx page with no code behind with a directive like the following below.
<%# page title="Test" language="C#" masterpagefile="Test.master"
autoeventwireup="true" inherits="TestScenario, TestScenario2" %>
Where do I need to look for the code (in VS)for the info that the Inherits attibute is pointing to.
Which page does the inherirtance refer to so that I can physically go look at what the page does.
This is a follow up to my previous question https://stackoverflow.com/questions/14278082/no-code-behind-aspx-page-page-directive.
Any info or few sentences on how a single page (with no code behind) is tied to the inherit attribute in the Page directive is much appreciated.

TestScenario, TestScenario2 is an assembly qualified type name.
Look for a class called TestScenario in a project that creates an assembly called TestScenario2. If you're lucky, the file will be at TestScenario2\TestScenario.cs, relative to your solution folder.

In Visual Studio, go to a .cs file and type TestScenario OR TestScenario2. Right click on the TestScenario OR TestScenario2 you typed and click on 'Go To Definition'. You can see where those classes are defined.
But in normal case when an ASP page is added with no .cs file, you can add a .cs file by placing the CodeFile="~/Path" in the Page directive.
Hope it helps.

Related

Passing aspx page via Stream

I have an aspx page that needs to be an embedded resource for a WCF project. An interfacing service serves the aspx/html/js files to the web browser via a Stream object. The problem I am having is getting the aspx page to display properly. I have tried setting the content type to "text/html", but when I do this, I get the following at the top of the page:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="Services.Interface.Views.WebForm" %>
Which is the first line of Index.aspx.
Since it's being served as an html file, the aspx "stuff" is ignored, I guess.
I've also tried setting the content type to "application/xhtml+xm" as some have suggested, but I get an error that says:
This page contains the following errors:
error on line 1 at column 2: StartTag: invalid element name
Below is a rendering of the page up to the first error.
I have tried taking out the ASP stuff from Index.aspx and changing it to an HTML file, and it works, but I need the ASP capabilities for accessing some settings in Web.config.
Is there a proper content type for aspx pages that I'm not aware of, or is something else going wrong? Thanks in advance

DotNetNuke DDRMenu set NodeSelector in code behind

I'm using DDRMenu in DotNetNuke to select a menu node from my site structure and display only a subnode in a specific navigation in my template
<%# Register TagPrefix="dnn" TagName="MENU" Src="~/DesktopModules/DDRMenu/Menu.ascx" %>
<dnn:MENU ID="MenuFooter" MenuStyle="MenuFooter" IncludeHidden="true" NodeSelector="FooterNavigation,0,1" runat="server" ></dnn:MENU>
Now I want to be able to set the NodeSelector attribute in the code behind file, because I want to be able to dynamically set the value on Page_Load
// load footer navigation node from a config file
protected void Page_Load(object sender, EventArgs e)
{
var footerNode = Config.Instance.Navigation.FooterNode;
MenuFooter.NodeSelector = footerNode + ",0,1";
}
But this doesn't work, as there is no NodeSelector attribute on System.Web.UI.UserControl.
Error 'System.Web.UI.UserControl' does not contain a definition for 'NodeSelector' and no extension method 'NodeSelector' accepting a first argument of type 'System.Web.UI.UserControl' could be found (are you missing a using directive or an assembly reference?) C:\Projects\eWolf2012\dev\DNN\Portals_default\Skins\JWEwolfSkin2012\Simple.ascx.cs 141 24 JWEwolfSkin2012
Is there any way to achieve this?
Kind regards
Usually the Menu.ascx in DDRMenu inherits from the DDRMenu SkinObject:
<%# Control Language="C#" AutoEventWireup="false" EnableViewState="false" Inherits="DotNetNuke.Web.DDRMenu.SkinObject" %>
Since you are talking about changing the code behind I guess that you are using a custom control that embeds the Menu.ascx. In which case you should be able to access the NodeSelector property since it exists in the SkinObject class.
What I am suspecting is happening is that your control type is not loaded correctly by the designer, and that it falls back on the UserControl type which doesn't have the NodeSelector property.
Try the following:
Include the DDRMenu assembly in your current project (because it won't load the type if it doesn't find the assembly), then rewrite the include to kick the designer into motion. I'm pretty confident this is the cause of the problem, but if not:
Fiddle with your src attribute and check in the *.designer file what type is defined.
Define it manually in your code-behind file instead of letting the designer do it.

Can a single ascx page use multiple codefile which are partial classes

Can we link up two partial classes to a single ascx page.
I have gone through some of the links but could not find a suitable solution for the same.
Suppose for example I am having files such as
Collection.ascx.cs and Collection.Search.cs
with Collection.ascx
I am having events like button click event, could it be placed in the partial class, as doing so would make the method unavailable.
My intention is to handle button click events and the dropdown change events in the partial class.
Yes, In WebApplication, It is a default nature for a .aspx (web page) and .ascx (user control).
These are by default comes with two .cs files, separating code in partial classes (filename.aspx.designer.cs and filename.aspx.cs with same partial class)
You can also add more .cs files to extend these partial class definition.
But in website, it will not work, for aspx or ascx.
Yes, the C# compiler rules for partial classes don't change because its ASP.NET. Just make sure your namespace and class name matches, the source file doesn't have to be a child of the ascx file in the Solution Explorer, but if you really want it to you can edit the project file and add the appropriate depends-on xml segment.
The answer locates at default.aspx 1st line:
Language="C#" CodeBehind="Default.aspx.cs" ...
will set every partial class working.
Instead,
Language="C#" CodeFile="Default.aspx.cs" ...
will lead partial class to wrong.
However, in vs2017 old-style-webForm you can only use CodeFile, so you have to try another way: just create a file ..\WebF8\App_Code\Class3.cs with content :
public static class Class3 {
public static int gg3=33;
}
then you can see Class3.gg3 in default.aspx.cs correctly.
Be careful, this Class3.cs file must be in \App_Code folder.

"System.Web.UI.MasterPage does not contain a definition..." ASP.NET error

EDIT: The main problem seemed to be that I was just doing "Add Existing Item" from an old web site project into an ASP.NET Web Application project. This caused so much trouble I just started from scratch, except that instead of adding existing items, I added new Master Pages and aspx pages to the project then populated them. The same problem persists.
I have a legacy project that is just a standard web site. I've started a new project as a web application and have transplanted in all the pages I need. However, I'm receiving 100+ errors that are comprised mostly of slightly different permutations of the following:
'System.Web.UI.MasterPage does not contain a definition for 'headerImage' (I get this in code-behind)
'MasterPage' does not contain a definition for 'imgHeader' (also this is in code-behind)
Regarding the first error, it's as though the project is not comprehending that the master page is set. I set the master page at the top of each one of my aspx pages like:
<%# page language="C#" masterpagefile="~/MasterPages/MasterPage.master" autoeventwireup="true" inherits="Equipment.aspx.cs" title="Untitled Page" %>
<%# MasterType VirtualPath="~/MasterPages/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<!-- some content -->
</asp:Content>
Also, I clearly expose a headerImage property in the ~/MasterPages/MasterPage.master code-behind:
public partial class MasterPage : System.Web.UI.MasterPage
{
#region Properties
private string _headerImage;
public string headerImage
{
get
{
return _headerImage;
}
set
{
_headerImage = (string)value;
}
}
// other stuff
}
And yet VS is still looking for this property in the System.Web.UI.MasterPage base class!
I've already checked out this post and it didn't solve my problem.
Thoughts? All feedback is appreciated. Thanks guys.
Good morning when you added the existing files to your new web application did you recreate them all from scratch or did you do a literal "Add Existing Item"? If so, then you should right click on each of the files and click the "Convert To Web Application" option.
Check what is the namespace of this.Master.
If it's System.Web.UI.MasterPage, try to rename your master page to a different name. This way you can isolate the problem.
My answer is similar to that of #mreyeros - however, my designer file was present already - it was that Vs didn't recognise the partial nature of the none- designer class and thus link the 2 together.
The fix I used was to remove the files from the project and re-add them using add existing. I did this in bulk and the newly added files behaved correctly and the error went away.

Inherit problem in asp.net

in my web application i copy and paste the code from other site to in my page also the source code starting form
when i run the application it is giving the error like this
Server Error in '/DomainIV' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
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 1: using System;
Line 2: using System.Data;
Line 3: using System.Web;
Source File: c:\Inetpub\wwwroot\DomainIV\WhoIs.aspx.cs Line: 1
this is my problem help me thank u.
In your aspx page there will be the following at the top:
<%# Page Language="C#" MasterPageFile="~/Test.Master" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="TestApp.Test" Title="Untitled Page" %>
In your .cs file your class will be defined like:
namespace TestApp
{
public partial class Test : System.Web.UI.Page
{
Make sure the inherits property in the aspx page matches the class definition in the .cs file. In the example above it is 'TestApp.Test' in the inherits property and the class must have the same namespace and classname TestApp and Test.
You probably copied the whole contents of one of the files and now the two pieces no longer match up.
My advice, create the new page with the same file name as the source.
Then copy and paste the codes into the new pages (APSX and code-behind). Works for me everytime.
In aspx page, there will be
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
And in .cs page
public partial class _Default : System.Web.UI.Page{}
Inherits attribute and the class name both should be same.
Hope this resolves the issue.
In your ASPX file, make sure the #Page declaration has an Inherits attribute that matches the full class name of the class in your code behind file. This declaration is usually the first line of the ASPX file. Also make sure that the class in your code behind file inherits System.Web.UI.Page and that it is not a sealed class.

Categories