The book must be wrong

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

I'm new to asp.net
I have the following aspx page listing below in a book that I'm reading.
The book is saying that this listing is showing a webbpageapplikation that
is using html-server controlls.

This must be wrong because this listing is using webbserver controlls
because you have the asp prefix.
So I just want to confirm with you that I'm is right ?

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

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

<BODY>
<H#> 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

//Tony
 
Tony Johansson said:
Hello!

I'm new to asp.net
I have the following aspx page listing below in a book that I'm reading.
The book is saying that this listing is showing a webbpageapplikation that
is using html-server controlls.

This must be wrong because this listing is using webbserver controlls
because you have the asp prefix.
So I just want to confirm with you that I'm is right ?

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

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

<BODY>
<H#> 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

//Tony

I think you are just getting a bit too caught up in terminology here Tony.
What you are showing here is an ASP .NET web page that has server-side code
wrtten into it along with "server controls" defined in it.

In the body of the page, there are indeed, what some would call HTML-Server
controls (the <asp:Button> and the <asp:Label>). These could also be called
a Server Controls, or Web Forms Controls. But, they can be called HTML
Server controls because they are server side repesentations of client side
HTML elements.

Personally, I only refer to something as an HTML Server Control when I take
some actual HTML element and mark it as being available to the server (thus,
a server-side class instance will represent it) by adding the runat="server"
and the id="someName" attributes to the HTML element. For all other server
controls, I just call them Server Controls.

In the end though, what's important is that they are Server controls, rather
then client controls.

-Scott
 
Hello!

I have two question
What is the difference if I have this attribute runat="server" compare to
not having it for this web server control Button

<asp:Button id=btnMyButton
runat="server"
Text="My button"
onclick="btnMyButton_Click" />

Here I have what I call a HTML server control. What would be the difference
in this case if I remove this runat="server"
for this input control. ?
<input id="Name"
type=text
size=50
runat="server"

//Tony
 
I'm new to asp.net
I have the following aspx page listing below in a book that I'm
reading. The book is saying that this listing is showing a
webbpageapplikation that is using html-server controlls.

This must be wrong because this listing is using webbserver controlls
because you have the asp prefix.
So I just want to confirm with you that I'm is right ?

The author did not use standard terminology, so I would agree with you, but
would not get overly bent out of shape, as none of the terminology used is
100% consistent.

These are definitely NOT controls in the HTML web controls namespace and
they are what we would normally term server controls, not HTML server
controls.

Technically, you can use HTML controls as server controls, as well, if you
add runat="server" to them, so that is probably what is confusing you.

I agree with Scott that you should not let the terminology get in the way
of learning. On the other hand, feel free to float questions, as that is
one way to learn.

Peace and Grace,

--
Gregory A. Beamer
Microsoft MVP (Visual C# Architecture)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

**********************************************
| Think outside the box! |
**********************************************
 
Tony Johansson said:
Hello!

I have two question
What is the difference if I have this attribute runat="server" compare to
not having it for this web server control Button

<asp:Button id=btnMyButton
runat="server"
Text="My button"
onclick="btnMyButton_Click" />

This is already known by the ASP .NET engine to be a server control based on
the <asp: syntax.
Here I have what I call a HTML server control. What would be the
difference in this case if I remove this runat="server"
for this input control. ?
<input id="Name"
type=text
size=50
runat="server"

Normally, this would be just a client side control, but the server sees the
runat="server" and the id="Name" on it and it knows to generate an instance
of a server-side control.

Both techniques will get you a server-side control to work with, but not the
*same* server-side control. The HTML version will offer only limited server
events and properties than the ASP .NET Server control will.

-Scott
 
Hello!

You say that if I have a webbserver control like this Button below it is
already a server side control.
What is the practice here is to use runat=server or skip this runat=server
because this runat=server doesn't
add anything because as you mentioned it is already a server side control.
<asp:Button id=btnMyButton
runat="server"
Text="My button"
onclick="btnMyButton_Click" />


//Tony
 
Tony said:
What is the practice here is to use runat=server or skip this
runat=server because this runat=server doesn't
add anything because as you mentioned it is already a server side
control. <asp:Button id=btnMyButton
runat="server"
Text="My button"
onclick="btnMyButton_Click" />

If you omit the runat="server" then it will not work.

Andrew
 
What is the practice here is to use runat=server or skip this
runat=server because this runat=server doesn't
add anything because as you mentioned it is already a server side
control.

What I mean is standard HTML controls have an analog in the .NET space if
you use runat=server.

<input type="button" runat="server"

will become a HtmlButton control from the .NET standpoint. Without
runat=server, you will end up with a standard HTML "control".

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top