#region License
/**
* Ingenious MVC : An MVC framework for .NET 2.0
* Copyright (C) 2006, JDP Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: - Kent Boogaart (kentcb@internode.on.net)
*/
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI.WebControls;
using Ingenious.Mvc;
using Ingenious.Mvc.Util;
using Ingenious.Mvc.Web.Forms.Views;
namespace Ingenious.Mvc.Web.Forms.UI.WebControls{
public class NavigateLinkButton : LinkButton
{
private Id<IView> _viewId;
private object _viewData;
[DefaultValue("")]
[Category("Behavior")]
[Description("The ID of the view to which this link button will navigate to when clicked.")]
[TypeConverter(typeof(IdConverter<IView>))]
public Id<IView> ViewId
{
get
{
return _viewId;
}
set
{
_viewId = value;
}
}
[DefaultValue(null)]
[Category("Behavior")]
[Description("Any extraneous data to be passed to the view when the navigation occurs.")]
public object ViewData
{
get
{
return _viewData;
}
set
{
_viewData = value;
}
}
public event EventHandler<NavigatedEventArgs> Navigated;
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
ArgumentHelper.AssertNotEmpty(_viewId, "ViewId");
PageBase pageBase = Page as PageBase;
ExceptionHelper.ThrowIf(pageBase == null, "OnClick.incorrectPageType", Page.GetType().FullName, typeof(PageBase).FullName);
//look up the navigator and enact the navigation
pageBase.Task.Manager.GetNavigatorForTask(pageBase.Task).NavigateTo(_viewId, _viewData);
OnNavigated();
}
protected virtual void OnNavigated()
{
EventHelper.Raise(Navigated, this, new NavigatedEventArgs(_viewId, _viewData));
}
}
}
|