简体   繁体   中英

ASP.NET How can I use my class in Page_Load of my aspx.cs

How can I use my class in Page_Load of my aspx.cs file and why can`t I use it at the moment ? I added my namespace in my aspx.cx but give me error.

My class is:

public static class DateTimeExtensions
    {
        public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
        {
            int diff = dt.DayOfWeek - startOfWeek;
            if (diff < 0)
            {
                diff += 7;
            }
            return dt.AddDays(-1 * diff).Date;
        }
    }

In my aspx file it looks like following

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="VacationDays.Default" uiCulture="sv" %>
 <% using VacationDays; %>

I get error message:

'VacationDays' is a namespace but is used like a variable

I would appreciate for any help!

In code behind ie mypage.aspx.cs , use

using VacationDays;

In mypage.aspx (as mentioned by Garbriel Luci)

<%@ Import namespace="VacationDays" %>

Hope this helps!

The syntax of a using statement in an aspx file is different. Try this:

<%@ Import namespace="VacationDays" %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM