Skip to content

Instantly share code, notes, and snippets.

@abhi1010
Created May 6, 2014 07:28
Show Gist options
  • Save abhi1010/135e9bbf44f3d9a53cb8 to your computer and use it in GitHub Desktop.
Save abhi1010/135e9bbf44f3d9a53cb8 to your computer and use it in GitHub Desktop.
Custom Web Controls - Full Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing.Design;
namespace CodersDigest.Web.UI.ExtendedControls
{
[ToolboxData("<{0}:HoverImageButton runat=server></{0}:HoverImageButton>")]
public class HoverImageButton : ImageButton
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
[UrlProperty(), Editor("System.Web.UI.Design.UrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)), Themeable(false)]
public string ImageHoverUrl
{
get
{
String s = (String)ViewState["ImageHoverUrl"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["ImageHoverUrl"] = value;
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
string resourceName = "ExtendedControls.HoverImageButtonJS.js";
ClientScriptManager cs = this.Page.ClientScript;
cs.RegisterClientScriptResource(typeof(CodersDigest.Web.UI.ExtendedControls.HoverImageButton), resourceName);
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Attributes.Add("onmouseover", "ShowImageHoverButton(this, '" + this.ResolveUrl(ImageHoverUrl) + "')");
this.Attributes.Add("onmouseout", "ShowImageHoverButton(this, '" + this.ResolveUrl(ImageUrl) + "')");
}
protected override void RenderContents(HtmlTextWriter output)
{
this.Attributes.Add("onmouseover", "ShowImageHoverButton(this, '" + this.ResolveUrl(ImageHoverUrl) + "')");
this.Attributes.Add("onmouseout", "ShowImageHoverButton(this, '" + this.ResolveUrl(ImageUrl) + "')");
output.Write(Text);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment