ASP.NET 2.0 - Two ASPX files with one code file

R

rampabbaraju

In my project I have two web pages with the same functionality, but the
controls are placed in different places in each page. Application
compiles and runs properly and produces the results I am expecting. But
the designer shows errors. Is it OK to do that way or not?

My two files are like this

Default.aspx-----
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" /></div>
</form>
</body>
</html>

test.aspx-----

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button BackColor="Aqua" ID="Button1" runat="server"
Text="Button" /></div>
</form>
</body>
</html>

Code file---
using System;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Button1.Text = "red";
}
}
 
L

Laurent Bugnion

Hi,

In my project I have two web pages with the same functionality, but the
controls are placed in different places in each page. Application
compiles and runs properly and produces the results I am expecting. But
the designer shows errors. Is it OK to do that way or not?

I do that often, and it works fine AFAICS. However, I do not use the
designer, maybe that's the reason.

I think that the designer uses the "codebehind" attribute to locate the
code behind file. Maybe you can try to set this attribute in both ASPX
files and see if that works better.

Greetings,
Laurent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top