Some easy question about ASP.NET application

T

Tony Johansson

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 it not any class like it is in the window form like
this
public class Test : Forms
{
....
}
I thought that everything must be put within a class

I created a project using template ASP.NET Web Application
then a class was created like this.
public class WebForm1 : System.Web.UI.Page
{
....
}

Now to my question :
1.So is it possible to create a ASP.NET application without putting the code
within a class. Like my ASP.NET application example below.
2.If I want to put my ASP.NET application below within a class how would it
look like then?
3.What is the difference for my ASP.NET application below if I put the code
in a class or have it as it is now without any class.


<%@ Page Language="C#" %>

<HTML>
<HEAD>
<SCRIPT RUNAT="SERVER">
protected void btnMyButton_Click(object Source, EventArgs e)
{
lblMyLabel.Text = "Some <b> clicked </b> on the button!";
}
</SCRIPT>
</HEAD>

<BODY>
<H3>A simple webbformexample</H3>
<FORM RUNAT=SERVER>
<asp:Button id=btnMyButton
runat="server"
Text="My button"
onclick="btnMyButton_Click" />
<br>
<br>
<asp:Label id=lblMyLabel
runat=server />
</FORM>
</BODY>
</HTML>The form upper border
 
K

Kumar Reddi

Tony said:
Now to my question :
1.So is it possible to create a ASP.NET application without putting the code
within a class. Like my ASP.NET application example below.

Yes.. as you did
2.If I want to put my ASP.NET application below within a class how would it
look like then?

I am guessing you are talking about Code-behind model of creating
asp.net application. And Visual Studio.Net uses the code-behind model,
as you saw from your WebForm1 example
3.What is the difference for my ASP.NET application below if I put the code
in a class or have it as it is now without any class.

The difference would be, when is the code compiled.

In code-Behind model, you compile all the code as a DLL and put it in a
bin folder and deploy. In an in-line coding, like your example below,
the code is compiled only at the time of actualy request.

and some other differences would be, clean code-separation from HTML
and also, by going with code-behind model you can protect intellectual
property, by not leaving the actual code in the aspx page, as it is
done in the inline coding

THere could be several other differences, but please do a google search
for "inline coding vs codebehind". You would find tons of literature
<%@ Page Language="C#" %>

<HTML>
<HEAD>
<SCRIPT RUNAT="SERVER">
protected void btnMyButton_Click(object Source, EventArgs e)
{
lblMyLabel.Text = "Some <b> clicked </b> on the button!";
}
</SCRIPT>
</HEAD>

<BODY>
<H3>A simple webbformexample</H3>
<FORM RUNAT=SERVER>
<asp:Button id=btnMyButton
runat="server"
Text="My button"
onclick="btnMyButton_Click" />
<br>
<br>
<asp:Label id=lblMyLabel
runat=server />
</FORM>
</BODY>
</HTML>The form upper border




begin 666 p.gif
M1TE&.#EAU0`.`)$``/___P``_P`````*(R'Y! $`````+ ````#5``X```+_
MA(^IR^T/HYRTVHNAR+P?L7EB%P1&V: C!;9?UX:KA@WV;=QXK@^\7BFI`*JA
MPG@T'9 8&2#DM#BCLP558E-D>=S$UC)4,A?CI?)TYDP-LMB+K;BR77/0T_ZA
MUZ/N._YYY^4C>+#U53@8E&:&9E8DMDB4%B;$^&BT!A@'QXD@EP#UIIGYJ6DZ
M>G78!6"8B'@Q]MAX(EF;A"!K*X22>QJZ"7?5]N?9V=8YZG#\)M<SZ(P(Q-HS
M$0LYZQB)MIO;JWL6L^SWMR$,FD<G#A6.;B6:O* Z/?]*V-#'>/N=L,M@=%G)
MUK: IY@5"^;N("E1O^X!\X4,@;Q6]22ZJJ:MVR)>:1DG7>/G,>$YB.]&<EIH
M#!F5E>\:VK-8;^)%C$MF]3+A#=L^6@(%@A/)KB0H/>,:JM.#[^ >H:LJSH,V
M31I&2MCZ^=P8<F"^;")*5?D*%@.WL63+FCV+-JVV"5[#NGT+-Z[<N73KVIU1
#```[
`
end
 
B

bruce barker \(sqlwork.com\)

with 2.0 there is no real difference between inline and code behind, as all
compiling is done by the aspnet_compiler. the code behind is a partial
class, so its like an include with the form code.

its just a matter of taste.

-- bruce (sqlwork.com)


Kumar Reddi said:
Tony said:
Now to my question :
1.So is it possible to create a ASP.NET application without putting the
code
within a class. Like my ASP.NET application example below.

Yes.. as you did
2.If I want to put my ASP.NET application below within a class how would
it
look like then?

I am guessing you are talking about Code-behind model of creating
asp.net application. And Visual Studio.Net uses the code-behind model,
as you saw from your WebForm1 example
3.What is the difference for my ASP.NET application below if I put the
code
in a class or have it as it is now without any class.

The difference would be, when is the code compiled.

In code-Behind model, you compile all the code as a DLL and put it in a
bin folder and deploy. In an in-line coding, like your example below,
the code is compiled only at the time of actualy request.

and some other differences would be, clean code-separation from HTML
and also, by going with code-behind model you can protect intellectual
property, by not leaving the actual code in the aspx page, as it is
done in the inline coding

THere could be several other differences, but please do a google search
for "inline coding vs codebehind". You would find tons of literature
<%@ Page Language="C#" %>

<HTML>
<HEAD>
<SCRIPT RUNAT="SERVER">
protected void btnMyButton_Click(object Source, EventArgs e)
{
lblMyLabel.Text = "Some <b> clicked </b> on the button!";
}
</SCRIPT>
</HEAD>

<BODY>
<H3>A simple webbformexample</H3>
<FORM RUNAT=SERVER>
<asp:Button id=btnMyButton
runat="server"
Text="My button"
onclick="btnMyButton_Click" />
<br>
<br>
<asp:Label id=lblMyLabel
runat=server />
</FORM>
</BODY>
</HTML>The form upper border




begin 666 p.gif
M1TE&.#EAU0`.`)$``/___P``_P`````*(R'Y! $`````+ ````#5``X```+_
MA(^IR^T/HYRTVHNAR+P?L7EB%P1&V: C!;9?UX:KA@WV;=QXK@^\7BFI`*JA
MPG@T'9 8&2#DM#BCLP558E-D>=S$UC)4,A?CI?)TYDP-LMB+K;BR77/0T_ZA
MUZ/N._YYY^4C>+#U53@8E&:&9E8DMDB4%B;$^&BT!A@'QXD@EP#UIIGYJ6DZ
M>G78!6"8B'@Q]MAX(EF;A"!K*X22>QJZ"7?5]N?9V=8YZG#\)M<SZ(P(Q-HS
M$0LYZQB)MIO;JWL6L^SWMR$,FD<G#A6.;B6:O* Z/?]*V-#'>/N=L,M@=%G)
MUK: IY@5"^;N("E1O^X!\X4,@;Q6]22ZJJ:MVR)>:1DG7>/G,>$YB.]&<EIH
M#!F5E>\:VK-8;^)%C$MF]3+A#=L^6@(%@A/)KB0H/>,:JM.#[^ >H:LJSH,V
M31I&2MCZ^=P8<F"^;")*5?D*%@.WL63+FCV+-JVV"5[#NGT+-Z[<N73KVIU1
#```[
`
end
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top