Codebehind -> Src?

K

Krunom Ancini

Hi,

im just the beginner and im using c#-codebehind in my
asp.net-application....
What should i do to make my application work "without" code-behind (without
dll.-s in bin-folder)?

I was googling something about Src instead of Codebehind (in @page
directive) but i dont know where to start...

Please help,

thanks in advance,

Krunom.
 
G

Guest

Hi,

You need to write all the code that you might write in the code behind file,
directly to the HTML code area.
something similar to java scripts that you write on the page.

regds,
 
D

Dennis Myrén

Put this at the top of the ASPX file:
<%@ Page language="C#" src="YourCodebehind.aspx.cs" AutoEventWireup="false"
Inherits="YourNamespace.YourCodebehind" %>

Write the codebehind class as normally.

Server code may also be embedded directly at the top of the ASPX page,
although i would not recommend it.
<script language="C#" runat="server">
// Code
</script>
 
E

Eliyahu Goldin

Krunom,

As a beginner you should follow normal ways. If you wish, you can place all
the code inside .aspx file, although it will certainly delay your promoting
from the "beginner grade". But what in the world do you have against dlls in
bin folder?

Eliyahu
 
T

Tampa.NET Koder

What you need to ask yourself is What is your development envorinment? If
its VS then leverage the tool. The Codebehind attribute is specific to VS
only. ASP.NET ignores this at runtime. You can use the src attribute; but
then you are telling VS that you dont want to have your pages pre-compiled.

If its Visual Notepad, then the SRC attribute might be a little better.
Your pages are not going to be pre-compiled, so you might as well let the
..net framework compile it at runtime.
 
K

Krunom Ancini

But what in the world do you have against dlls in
bin folder?

I have nothing, but my web-host does :(

Do you know any free asp.net web-host with codebehind-support? :)
 
K

Krunom Ancini

Tampa.NET Koder said:
What you need to ask yourself is What is your development envorinment?

It's VS!
You can use the src attribute

in @page directive instead of "Codebehind" i should only write "src" and
thats it? so simple?
then you are telling VS that you dont want to have your pages
pre-compiled.

And what is the bad thing about it? speed? data-amount?
 
K

Krunom Ancini

Dennis Myrén said:
Put this at the top of the ASPX file:
<%@ Page language="C#" src="YourCodebehind.aspx.cs"
AutoEventWireup="false" Inherits="YourNamespace.YourCodebehind" %>

Write the codebehind class as normally.

Sounds simple :)
and i tried it and it didnt work but ill keep trying :)

Thanks...
 
G

Guest

You do not have to have a CodeBehind, but the page will have to follow
certain rules. You can wire events either programatically or declaratively.

EXAMPLE 1: Programatic
-----------------------------
<%@ Page language="c#" AutoEventWireup="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>UglyPage</title>
<script language="C#" runat="server">
// Page Load
private void Page_Load(object sender, System.EventArgs e)
{
}

override protected void OnInit(EventArgs e)
{
//Need an init to start the page
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.btnFill.Click += new System.EventHandler(this.btnFill_Click);
this.Load += new System.EventHandler(this.Page_Load);

}

private void btnFill_Click(object sender, System.EventArgs e)
{
txtFill.Text = btnFill.Text;
}
</script>

</HEAD>
<body>

<form id="Form1" method="post" runat="server">

<h1>This is an ugly page</h1>
<P><asp:Button id=btnFill runat="server" Text="Click me to fill text
box"></asp:Button><asp:TextBox id=txtFill runat="server"></asp:TextBox></P>

</form>

</body>
</HTML>

EXAMPLE 2: Declarative
----------------------------
<%@ Page language="c#" AutoEventWireup="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>UglyPage</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">

<script language="C#" runat="server">
private void btnFill_Click(object sender, System.EventArgs e)
{
txtFill.Text = btnFill.Text;
}
</script>

</HEAD>
<body>

<form id="Form1" method="post" runat="server">

<h1>This is an ugly page</h1>
<P><asp:Button id=btnFill runat="server" Text="Click me to fill text box"
OnClick="btnFill_Click"></asp:Button><asp:TextBox id=txtFill
runat="server"></asp:TextBox></P>

</form>

</body>
</HTML>

Wiring
OnClick="btnFill_Click" = declarative
this.btnFill.Click += new System.EventHandler(this.btnFill_Click); =
programatic

The src="" still uses a "CodeBehind" file, but it is dynamically compiled
when the page is hit rather than precompiled to IL when you deploy. Src=""
does not work in Visual Studio .NET, so do not use it if you are heading that
route.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 

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

Similar Threads


Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top