In the edit control of a module I am writing I use two CommandButton controls from DotNetNuke.UI.WebControls. The Markup looks like:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyModuleEdit.ascx.cs"
Inherits="MyCompany.DNN.Modules.MyModule.UI.MyModuleEdit" %>
<%@ Register Assembly="DotNetNuke" Namespace="DotNetNuke.UI.WebControls" TagPrefix="dnn" %>
...
<dnn:CommandButton ID="CancelButton" runat="server" CausesValidation="false"
ResourceKey="cmdCancel" CssClass="CommandButton"
ImageUrl="~/images/action_export.gif"
OnClick="CancelButton_Click" />
...
and the code behind:
namespace MyCompany.DNN.Modules.MyModule.UI
{
public partial class MyModuleEdit : PortalModuleBase
{
...
protected void CancelButton_Click(object sender, EventArgs e)
{
try
{
Response.Redirect(Globals.NavigateURL(), true);
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
...
}
}
When I use an asp:LinkButton control insted of the dnn:CommandButton, the thing works a expected and returns to the module's main view control. When I use the dnn:CommandButton, it fires a postback but does not return to the view control. In debug mode I recognized that the eventhandler is never executed. When I delete the event handler from the code there is no runtime error saying that the member CancelButton_Cllick dows not exist.
I also looked at the source code from the DNN Links Module, it is done in the exactly same way as here (only in VB insted of C#).
What works is the following code:
...
<dnn:CommandButton ID="CancelButton" runat="server" CausesValidation="false"
ResourceKey="cmdCancel" CssClass="CommandButton"
ImageUrl="~/images/action_export.gif"
OnInit="CancelButton_Init" />
...
and
...
protected void CancelButton_Init(object sender, EventArgs e)
{
this.CancelButton.Click += new EventHandler(CancelButton_Click);
}
protected void CancelButton_Click(object sender, EventArgs e)
{
try
{
Response.Redirect(Globals.NavigateURL(), true);
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
...
Any ideas?
Michael