473,383 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Question About Code Behind

SAI
I have 2 files which are copied from Microsoft for testing code behind.
But always show error "Parser Error Message: Could not load type 'MyClass'."
and highlight the aspx file code, Is my server has problem? thx.

Line 1: <%@ Page Language="C#" Inherits="MyClass" %>

aspx file content :
<%@ Page Language="C#" Inherits="MyClass" %>
<html>
<head>
</head>
<body>
<form id="MyForm" runat="server">
<asp:textbox id="MyTextBox" runat="server" text="Hello
World"></asp:textbox>
<asp:button id="MyButton" onclick="MyButton_Click" runat="server"
text="Echo Input"></asp:button>
<asp:Label id="MyLabel" runat="server"></asp:Label>
</form>
</body>
</html>

cs file content :
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyStuff
{
public class MyClass : Page
{
protected System.Web.UI.WebControls.Label MyLabel;
protected System.Web.UI.WebControls.Button MyButton;
protected System.Web.UI.WebControls.TextBox MyTextBox;

public void MyButton_Click(Object sender, EventArgs e)
{
MyLabel.Text = MyTextBox.Text.ToString();
}
}
}

Nov 19 '05 #1
3 1165
You must compile the code-behind before attempting to inherit.

Also, if you're inheriting from page, the format is as follows :

<%@ Import Namespace="MyNameSpace" %>
<%@ Page language="C#" Inherits="MyNameSpace.MyClass" %>

For you, that translates into :
<%@ Import Namespace="MyStuff" %>
<%@ Page language="C#" Inherits="MyStuff.MyClass" %>


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"SAI" <te**@test.com> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl...
I have 2 files which are copied from Microsoft for testing code behind.
But always show error "Parser Error Message: Could not load type 'MyClass'."
and highlight the aspx file code, Is my server has problem? thx.

Line 1: <%@ Page Language="C#" Inherits="MyClass" %>

aspx file content :
<%@ Page Language="C#" Inherits="MyClass" %>
<html>
<head>
</head>
<body>
<form id="MyForm" runat="server">
<asp:textbox id="MyTextBox" runat="server" text="Hello World"></asp:textbox>
<asp:button id="MyButton" onclick="MyButton_Click" runat="server" text="Echo
Input"></asp:button>
<asp:Label id="MyLabel" runat="server"></asp:Label>
</form>
</body>
</html>

cs file content :
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyStuff
{
public class MyClass : Page
{
protected System.Web.UI.WebControls.Label MyLabel;
protected System.Web.UI.WebControls.Button MyButton;
protected System.Web.UI.WebControls.TextBox MyTextBox;

public void MyButton_Click(Object sender, EventArgs e)
{
MyLabel.Text = MyTextBox.Text.ToString();
}
}
}


Nov 19 '05 #2
SAI
I use following method to compile. Is it right? thanks.

csc.exe /out:mycodebehind.dll /t:library mycodebehind.cs
"Juan T. Llibre" <no***********@nowhere.com> ¼¶¼g©ó¶l¥ó·s»D:%2***************@TK2MSFTNGP10.phx. gbl...
You must compile the code-behind before attempting to inherit.

Also, if you're inheriting from page, the format is as follows :

<%@ Import Namespace="MyNameSpace" %>
<%@ Page language="C#" Inherits="MyNameSpace.MyClass" %>

For you, that translates into :
<%@ Import Namespace="MyStuff" %>
<%@ Page language="C#" Inherits="MyStuff.MyClass" %>


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"SAI" <te**@test.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I have 2 files which are copied from Microsoft for testing code behind.
But always show error "Parser Error Message: Could not load type
'MyClass'."
and highlight the aspx file code, Is my server has problem? thx.

Line 1: <%@ Page Language="C#" Inherits="MyClass" %>

aspx file content :
<%@ Page Language="C#" Inherits="MyClass" %>
<html>
<head>
</head>
<body>
<form id="MyForm" runat="server">
<asp:textbox id="MyTextBox" runat="server" text="Hello
World"></asp:textbox>
<asp:button id="MyButton" onclick="MyButton_Click" runat="server"
text="Echo Input"></asp:button>
<asp:Label id="MyLabel" runat="server"></asp:Label>
</form>
</body>
</html>

cs file content :
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyStuff
{
public class MyClass : Page
{
protected System.Web.UI.WebControls.Label MyLabel;
protected System.Web.UI.WebControls.Button MyButton;
protected System.Web.UI.WebControls.TextBox MyTextBox;

public void MyButton_Click(Object sender, EventArgs e)
{
MyLabel.Text = MyTextBox.Text.ToString();
}
}
}



Nov 19 '05 #3
Yes, and if you need to reference a .Net Framework class,
add /r: classname.dll /r:anotherclassname.dll to the command :

csc.exe /t:library /r:system.dll /r:system.web.dll /out:cb.dll cb.cs

I shortened the filename and dll name to fit the command in one line.
Substitute your own names, of course.

If you want a number of files compiled into a single assembly, just put
all your .cs files into a directory and use a wildcard in the command :

csc.exe /t:library /r:system.dll /r:system.web.dll /out:cb.dll *.cs

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"SAI" <te**@test.com> wrote in message news:uP**************@TK2MSFTNGP12.phx.gbl...
I use following method to compile. Is it right? thanks.

csc.exe /out:mycodebehind.dll /t:library mycodebehind.cs
"Juan T. Llibre" <no***********@nowhere.com>
¼¶¼g©ó¶l¥ó·s»D:%2***************@TK2MSFTNGP10.phx. gbl...
You must compile the code-behind before attempting to inherit.

Also, if you're inheriting from page, the format is as follows :

<%@ Import Namespace="MyNameSpace" %>
<%@ Page language="C#" Inherits="MyNameSpace.MyClass" %>

For you, that translates into :
<%@ Import Namespace="MyStuff" %>
<%@ Page language="C#" Inherits="MyStuff.MyClass" %>


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"SAI" <te**@test.com> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl...
I have 2 files which are copied from Microsoft for testing code behind.
But always show error "Parser Error Message: Could not load type 'MyClass'."
and highlight the aspx file code, Is my server has problem? thx.

Line 1: <%@ Page Language="C#" Inherits="MyClass" %>

aspx file content :
<%@ Page Language="C#" Inherits="MyClass" %>
<html>
<head>
</head>
<body>
<form id="MyForm" runat="server">
<asp:textbox id="MyTextBox" runat="server" text="Hello World"></asp:textbox>
<asp:button id="MyButton" onclick="MyButton_Click" runat="server" text="Echo
Input"></asp:button>
<asp:Label id="MyLabel" runat="server"></asp:Label>
</form>
</body>
</html>

cs file content :
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyStuff
{
public class MyClass : Page
{
protected System.Web.UI.WebControls.Label MyLabel;
protected System.Web.UI.WebControls.Button MyButton;
protected System.Web.UI.WebControls.TextBox MyTextBox;

public void MyButton_Click(Object sender, EventArgs e)
{
MyLabel.Text = MyTextBox.Text.ToString();
}
}
}




Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: John | last post by:
Hi, I have an asp.net form where if the user enters an incorect date I change the color of the textbox to red and also display a label field with a message saying the date is invalid. What I...
12
by: Karl Hungus | last post by:
If I use a code behind class for an aspx page, what is the best way to get data from the codebehind class into my aspx page? I know about databinding, but is there a more basic way of just...
5
by: Dot net work | last post by:
Hi, Is it possible to do a form POST and also redirect to a different url, using code behind? I don't think response.redirect will work because that doesn't post form data. I don't think...
3
by: Derek Martin | last post by:
Hi list, I have been doing VB.Net for quite a while now and just now getting into the forray of ASP.Net using VS2003. I have created our development website and now we are ready to start putting...
2
by: dinesh | last post by:
I'm converting an app written using the pure .net framework from command line, to Visual studio 2003. Having a problem with the datalist that wasnt there before: ...
2
by: Tony Johansson | last post by:
Hello! I'm new to ASP.NET application but I have been using C# windows form for one year. I'm reading a book about Webbdevelopment. Below is a small ASP.NET application. I just wonder why is...
6
by: Bill44077 | last post by:
Hi, I am new to the MVP pattern and one of the main reasons that we are going this route is because we are doing Scrum with 30 day sprints - so we have a continually morphing design. We are...
9
by: Gilbert | last post by:
Hi, In the code-behind, i have this function: Public Function myfunction(ByVal myvar As Object) As String dim x as string = myvar ..... Return x End Function
1
by: archana | last post by:
Hi all, I am new to asp.net. I have one question regarding code- behind model. I have written page_load event in code behind as well as in aspx page. Means i am doing mixing of code-behind...
3
by: pb | last post by:
Hi, I have built a page with some generic functions in the code behind - all works fine. I then wanted to put these functions in their own code modules, so in the app_code folder I created...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.