Issue with asp code behind

A

avanti

Hi,

I have an ASP page with the page directive:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

It has some controls defined like:
<p> <asp:Button ID="SearchButton" OnClick = "SearchButton_Click"
CssClass="button" Text="Search" runat="server" /> </p>

The code behind has the control defined as:
protected TextBox SearchTextBox;

I am getting an error: "SearchtextBox already defined".

If I remove it, I get "SerachTextBox" no defined. Am I missing
something?

Thanks.
 
L

Laurent Bugnion

Hi,
Hi,

I have an ASP page with the page directive:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

It has some controls defined like:
<p> <asp:Button ID="SearchButton" OnClick = "SearchButton_Click"
CssClass="button" Text="Search" runat="server" /> </p>

The code behind has the control defined as:
protected TextBox SearchTextBox;

I am getting an error: "SearchtextBox already defined".

If I remove it, I get "SerachTextBox" no defined. Am I missing
something?

Thanks.

In 2.0, you don't need to explicitly declare the controls in the code
behind anymore like in 1.1. The compiler should take care of that for
you, by creating a <pagename>.aspx.designer.cs file in which all the
controls should be declared. This is possible because 2.0 introduced
partial classes in C#, so one class can be defined in more than one file.

So normally, if you add one control in your ASPX page, compile, then the
control should be added to the designer.cs file. Check that it's the
case (you must see the designer.cs file in your Solution explorer, you
must open it, and check that the control is actually available).

If it is not available, then I would rename your ASPX file to something
else, add a new ASPX file with the old name, and then copy paste the
controls from the old one to the new one. Sometimes (especially when you
convert 1.1 apps to 2.0), the designer.cs file doesn't work well.

HTH,
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

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top