开发者

How to reference page class from a code folder?

开发者 https://www.devze.com 2023-04-12 21:13 出处:网络
I have an ASP.NET website written in VB.NET and trying to add MVC to it. I managed to add controllers (to CS_Code folder) and make them running. However, I have to use some code from aspnet pages.

I have an ASP.NET website written in VB.NET and trying to add MVC to it.

I managed to add controllers (to CS_Code folder) and make them running. However, I have to use some code from aspnet pages.

When I try to call method from page I ma having compile time error

public CustomerFrontend.DefaultForm DefaultForm { get; set; }

Error:

The type or namespace name 'DefaultForm' could not be found (are you missing a using directive or an assembly reference?)

Page directive definition which proves than namespace is correct:

<%@ Page Language开发者_开发技巧="vb" ValidateRequest="false" 
                       EnableViewState="False" 
                       AutoEventWireup="false" 
                       Inherits="CustomerFrontend.DefaultForm" 
                       CodeFile="DefaultForm.aspx.vb" %>

Regardless the fact if I refer to fill name or short name.

Any ideas?


Try something like this instead:

DefaultForm page = HttpContext.Current.Handler as DefaultForm;
if (page != null)
{
    page.MyMethod();
}


Is "CustomerFrontend" the namespace of your application? Make sure you put the fully qualified path to the "DefaultForm" class.

0

精彩评论

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

关注公众号