the old HTML-ServerControl

T

Tony Johansson

Hello!

Below is three examples of the old HTML control where I have added
runat=server to make them available on the server
to be manipulated.
Now is there any reason to use these as server control instead of the new
asp control.?
I mean these old HTML control might be usable on the client but I can't see
any reason at all to use these as server control
because the new asp control is much better.

<input id="Name" style="position:absolute;" type="text"
size=50 runat="server" />

<input id="Password" style="position:absolute; top: 53px; left: 89px;"
type="password" size=50 runat="server"/>

<input id="Submit1" style="position:absolute; top: 83px; left: 63px;"
type="submit" value="Enter" size=30 OnServerClick="SubmitBtn_Click"
runat="server" />

//Tony
 
A

Arne Vajhøj

Below is three examples of the old HTML control where I have added
runat=server to make them available on the server
to be manipulated.
Now is there any reason to use these as server control instead of the new
asp control.?
I mean these old HTML control might be usable on the client but I can't see
any reason at all to use these as server control
because the new asp control is much better.

<input id="Name" style="position:absolute;" type="text"
size=50 runat="server" />

They so something relative different.

Try run the following .aspx:

<%@ import namespace="System.Collections.Generic" %>
<html>
<head>
<script language="C#" runat="server">
public class ControlInfo
{
public string Clazz { get; set; }
public string Name { get; set; }
public string Text { get; set; }
}
void Page_Load(Object sender, EventArgs e)
{
List<ControlInfo> lst = new List<ControlInfo>();
foreach(Control c in f.Controls)
{
if(c is LiteralControl)
{
lst.Add(new ControlInfo{Clazz=c.GetType().FullName,
Name="", Text=Server.HtmlEncode(((LiteralControl)c).Text)});
}
else
{
lst.Add(new ControlInfo{Clazz=c.GetType().FullName,
Name=c.ID, Text=""});
}
}
rep.DataSource = lst;
rep.DataBind();
}
</script>
</head>
<body>
<form id="f" runat=server>
<input type="text" id="f1" name="f1"/>
<br/>
<input type="text" id="f2" name="f2" runat="server"/>
<br/>
<asp:TextBox id="f3" runat="server"/>
<br/>
Controls:
<table border="1">
<asp:Repeater id="rep" runat="server">
<ItemTemplate>
<tr>
<td><%# Eval("Clazz") %></td>
<td><%# Eval("Name") %></td>
<td><%# Eval("Text") %></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</border>
</form>
</body>
</html>

You will see in "view source" that the 3 x input looks
very similar:

<input type="text" id="f1" name="f1"/>
<input name="f2" type="text" id="f2" />
<input name="f3" type="text" id="f3" />

But if you look at what controls ASP.NET is using (shown
in the repeater, then they are very different:

f1 is a System.Web.UI.LiteralControl with the HTML as simple text.

f2 is a System.Web.UI.HtmlControls.HtmlInputText.

f3 is a System.Web.UI.WebControls.TextBox.

HtmlControls og WebControls are fundamentally different. But
I am not sure that one is better than the other.

HtmlControls are a relative thin ASP.NET layer on top of
plain HTML.

WebControls are a designed to be GUI components.

I am not a ASP.NET expert so I am not the right person to
ask precisely when to use what.

The google term is:

webcontrols versus htmlcontrols

Arne
 

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

Top