Applet Graphical User Interface Event

Download Report

Transcript Applet Graphical User Interface Event

Chapter 6
Web Controls
Detailed descriptions of server controls provided by FCL.
Yingcai Xiao
Chapter 7
User Controls
Yingcai Xiao
User Controls
•
•
•
Custom controls built from HTML and server-side scripts.
Create your own tags and tag prefixes.
File.ASCX
A simple user control:
Hello.ascx
<h1>Hello, world</h1>
How to Use User Controls
• Usage (UserControlDemo.aspx)
<%@ Register TagPrefix="Xiao" TagName="Hello" src="Hello.ascx" %>
<html>
<body>
<form RunAt="server">
<Xiao:Hello RunAt="server" />
</form>
</body>
</html>
TagPrefix="Xiao" defines a new tag prefix.
TagName="Hello" defines a new tag
using src="Hello.ascx".
http://winserv1.cs.uakron.edu/xiaotest/UserControlDemo.aspx
Chapter 8
Custom Controls
Yingcai Xiao
Custom Controls
•
Custom-built server controls using only a server-side
language (no HTML).
•
Derived from System.Web.UI.Control.
•
Create your own tags and tag prefixes.
Custom Controls
• Creation (Hello.cs)
using System;
using System.Web.UI;
namespace WP
{
public class Hello : Control
{
protected override void Render (HtmlTextWriter writer)
{
writer.Write ("Hello, world");
}
}
}
Note: the Render method is required to be overridden.
Custom Controls
• Compilation: csc /target:library Hello.cs
Move Hello.dll to “bin” of the application directory.
• Usage
http://winserv1.cs.uakron.edu/xiaotest/CustomControlDemo.aspx
<%@ Register TagPrefix="win"
Namespace="WP"
Assembly="Hello" %>
<html>
<body>
<form RunAt="server">
<win:Hello RunAt="server" />
</form>
</body>
</html>