Library tutorials & articles
Using ASP.NET Server Controls
Controls
Server Controls
These controls are basically server side .NET components. The four types of server controls are HTML, ASP, Validation, and User. This article will not focus on the user control, it will be covered in a separate article later.
HTML Controls
These are your standard HTML controls with a few modifications that enable them to be used within ASP.NET. You can take any HTML control and add the ID and RUNAT attributes to make it a HTML server control.
<input type="text" id="txtName" runat="server"
size="40">
ASP.NET Controls
A set of server-side components that can generate HTML or JavaScript for your ASP.NET pages. They also give developers the ability to program to events that are not available with HTML controls. This is one of the biggest improvements to ASP. Another advantage of ASP.NET controls is the ability to bind them to a data source, with includes XML recordsets.
<% @Page language="C#" %>
<html>
<body>
<script language="C#" runat="server">
private void btnclick_click(object sender, EventArgs e)
{
lblresponse.Text = "You selected " + rgdemo.SelectedItem.Text;
}
</script>
<form runat=server>
<asp:label id="lblMessage" text="Which do you prefer"
runat="server" />
<asp:RadioButtonList id="rgdemo" runat="server">
<asp:ListItem selected="True">C##</asp:ListItem>
<asp:ListItem>Visual Basic</asp:ListItem>
<asp:ListItem>Delphi</asp:ListItem>
<asp:ListItem>C++</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:RadioButtonList>
<br><br>
<asp:button id="btnclick" text="Click Here"
onClick="btnclick_click" runat="server" />
<br><br>
<asp:label id="lblresponse" runat="server" />
</form>
</body>
</html>
|
Validation Controls
Validation controls attach to input controls, they work together to provide developers with the ability to check required fields, patterns, ranges, and other routine validation scenarios.
<% @Page language="C#" %>
<html>
<body>
<form runat=server action="validate.aspx">
<TABLE>
<TR>
<TD>
<asp:label id="lbltext" text="Type is a number greater than 10 "
runat="server"/>
<asp:Textbox id="txtnumber" runat="server" size="5" />
</TD>
<TD>
<asp:CompareValidator id="valtext" runat="server"
ForeColor="Red" ControlToValidate="txtnumber" Type="Integer"
ValueToCompare=10 Operator="GreaterThanEqual"
ErrorMessage="Please enter a number greater than 10!" />
</TD>
</TR>
</TABLE>
<asp:button type="submit" runat="server" id="btnsubmit"
text="Validate Me!" />
</form>
</body>
</html>
|
Related articles
Related discussion
-
Profile Class does not work after Translation
by converter2009 (1 replies)
-
what is the SQL Server Provider
by hayperaktib (1 replies)
-
Very Urgent regarding deleting the images from a folder
by Nanosteps (6 replies)
-
Java Script, File uploading on ftp server using java script code
by h_c_a_andersen (2 replies)
-
sharepoint calendar web part with events from sql table
by converter2009 (2 replies)
Related podcasts
-
StackOverflow uses ASP.NET MVC - Jeff Atwood and his technical team
Scott chats with Jeff Atwood of CodingHorror.com and most recently, StackOverflow.com. Jeff and Joel Spolsky and their technical team have created a new class of application using ASP.NET MVC. What works, what doesn't, and how did it all go down?
Events coming up
-
Mar
15
DevWeek 2010
London, United Kingdom
DevWeek is Europe’s leading independent conference for software developers, database professionals and IT architects, and features expert speakers on a wide range of topics, including .NET 4.0, Silverlight 3, WCF 4, Visual Studio 2010, REST, Windows Workflow 4, Thread Synchronization, ASP.NET 4.0, SQL Server 2008 R2, LINQ, Unit Testing, CLR & C# 4.0, .NET Patterns, WPF 4, F#, Windows Azure, ADO.NET, Entity Framework, Debugging, T-SQL Tips & Tricks, and more.
It would have made article more intresting if it was told which controls to be used in different conditions.
This thread is for discussions of Using ASP.NET Server Controls.