0

I am pretty new to c# and asp.net and I've encountered an error on a page with the error stating that

"There can be only one 'page' directive."

The code is as follows:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AddUser.aspx.cs" Inherits="OEPD.AddUser" %>

I have this page linked into another page using the <!-- #include file="~/Admin/AddUser.aspx --> function.This page is also using the MasterPage

<%@ Page Title=" Admin Home" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AdminHome.aspx.cs" Inherits="OEPD.Admin.AdminHome" %>

How do I fix this? So it not only links in, but works without errors?

Thanks in advance.

p.s this is my first question so I apologise if it seems a bit vague.

Rojalin Sahoo
  • 1,025
  • 1
  • 7
  • 18
karlb123
  • 17
  • 1
  • 6
  • 1
    Check http://forums.asp.net/p/1060242/1520215.aspx – MusicLovingIndianGirl Mar 22 '16 at 11:59
  • have a look on this article https://msdn.microsoft.com/en-us/library/fft2ye18.aspx. the page you are working is a content page which should be inherited from masterpage. If you created contentpage first then masterpage then have a look on http://stackoverflow.com/questions/5549638/how-to-add-master-page-to-already-created-webform – Rojalin Sahoo Mar 22 '16 at 12:04
  • Hi @RojalinSahoo I have a masterpage and both pages are inheriting it. The problem is occurring whenever I run the 'AdminHome' page while the 'AddUser' page is linked to it when it gives me the error. – karlb123 Mar 22 '16 at 12:13
  • @karlb123 how you are linking two page? is there any redirect option or any other way? – Rojalin Sahoo Mar 23 '16 at 12:21
  • @RojalinSahoo I have an 'Admin' page which is inheriting the Master Page but i'm trying to link an 'Add User' (also linked to master page) page into the 'Admin' Page. I'm not sure - I'm pretty stuck – karlb123 Mar 23 '16 at 13:09
  • You could create an adduser page and on admin page create a button with add user title. On button click you could redirect to add user page using Respone.Redirect or server.transfer – Rojalin Sahoo Mar 23 '16 at 14:03

1 Answers1

2

You shouldn't use #include file in asp.net, because it's a classic asp mechanizm and there are better ways of doing such things in new version of framework. In order to reuse your code in many pages you could rewrite your "inner page" to user control or your "outer page" as another master page. Here is more info about this topic: ASP.NET equivalent of server side includes

Community
  • 1
  • 1
Lesmian
  • 3,932
  • 1
  • 17
  • 28
  • 1
    can get clear idea about use of masterpage: https://msdn.microsoft.com/en-us/library/ehszf8ax(v=vs.100).aspx – Rojalin Sahoo Mar 22 '16 at 12:08
  • Hi @Lesmian appreciate your comment but the #include file function isn't working as it is flagging the "There can be only one 'page' directive." error. Any suggestions? – karlb123 Mar 23 '16 at 13:14