File: Control.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Control.ascx.cs" Inherits="Control" %>
Products:
Books
Toys
Sports
Furniture
File: Control.ascx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
public partial class LinkMenu : System.Web.UI.UserControl
{
public event LinkClickedEventHandler LinkClicked;
protected void lnk_Command(object sender, CommandEventArgs e)
{
if (LinkClicked != null)
{
LinkClickedEventArgs args = new LinkClickedEventArgs((string)e.CommandArgument);
LinkClicked(this, args);
if (!args.Cancel)
{
Response.Redirect(args.Url);
}
}
}
}
File: MenuHost.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="MenuHost.aspx.cs" Inherits="MenuHost"%>
<%@ Register TagPrefix="rntsoft" TagName="LinkMenu" Src="Control.ascx" %>
Menu Host
File: MenuHost.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
public class LinkClickedEventArgs : EventArgs
{
private string url;
public string Url
{
get { return url; }
set { url = value; }
}
private bool cancel = false;
public bool Cancel
{
get { return cancel; }
set { cancel = value; }
}
public LinkClickedEventArgs(string url)
{
Url = url;
}
}
public delegate void LinkClickedEventHandler(object sender, LinkClickedEventArgs e);
public partial class MenuHost : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.Params["product"] != null)
{
lblSelection.Text = "You chose: ";
lblSelection.Text += Request.Params["product"];
}
}
}
protected void LinkClicked(object sender, LinkClickedEventArgs e)
{
if (e.Url == "MenuHost.aspx?product=Furniture")
{
lblClick.Text = "This link is not allowed.";
e.Cancel = true;
}
}
}