如何写自定义类啊?并将类引用在页面上??
为了学习这个的用法我的写法如下
1. 创建DiamondHotSpot类
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace HotSpotTest
{
public class DiamondHotSpot : System.Web.UI.WebControls.HotSpot
{
public int CenterX
{
get
{
object val = ViewState["centerx"];
if (val == null)
return 0;
else
return (int)val;
}
set
{
ViewState["centerx"] = value;
}
}
public int CenterY
{
get
{
object val = ViewState["centery"];
if (val == null)
return 0;
else
return (int)val;
}
set
{
ViewState["centery"] = value;
}
}
public int Width
{
get
{
object val = ViewState["width"];
if (val == null)
return 0;
else
return (int)val;
}
set
{
ViewState["width"] = value;
}
}
public int Height
{
get
{
object val = ViewState["height"];
if (val == null)
return 0;
else
return (int)val;
}
set
{
ViewState["height"] = value;
}
}
protected override string MarkupName
{
get
{
return "poly";
}
}
public override string GetCoordinates()
{
return CenterX.ToString() + "," +
(CenterY - Height / 2).ToString() + "," +
(CenterX + Width / 2).ToString() + "," +
CenterY.ToString() + "," +
CenterX.ToString() + "," +
(CenterY + Height / 2).ToString() + "," +
(CenterX - Width / 2).ToString() + "," +
CenterY.ToString();
}
}
}
2. 在页面写 Register 指令
<%@ Register TagPrefix="HotSpotTest" Namespace="HotSpotTest" %>
<asp:ImageMap ID="ImageMap1" runat="server" ImageUrl="hotspot.jpg" HotSpotMode="PostBack">
<HotSpotTest:DiamondHotSpot CenterX="100" CenterY="50" Height="100" Width="50" />
</asp:ImageMap>
可总是有问题,如何编写自定义类以及自定义控件,并将它们引用到页面上呀
[解决办法]
没有定义assembly吧,添加一个assembly属性试试