Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Problem with CommandButton (DotNetNuke.UI.WebControls)Problem with CommandButton (DotNetNuke.UI.WebControls)
Previous
 
Next
New Post
7/27/2008 3:48 AM
 

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


Michael Tobisch
DNN★MVP

dnn-Connect.org - The most vibrant community around the DNN-platform
 
New Post
7/27/2008 1:48 PM
 

Hey Michael,

This makes sense, as you'll need to either wire up the event in the markup or in the code behind. However, defining a new event for OnInit to wire up the event is going a little bit out of your way. You should be able to put the contents of the CancelButton_Init handler into a "page lifecycle" event that already exists in your code behind and remove the OnInit="CancelButton_Init" from the markup. It's my preference to wire up events in the code behind rather than in the markup ("separation of concerns...").

Here is an example from a project I had close at hand:

        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += this.Page_Load;
            this.SearchButton.Click += this.SearchButton_Click;
            this.ReplaceButton.Click += this.ReplaceButton_Click;
        }

When you're using the LinkButton - do you notice that the event handler is wired up in the markup for you by default?

Hope that helps,

Ian


Software Engineer
Co-Founder, dnnGallery
Stack Overflow: Ian Robinson
Twitter: @irobinson
Linked In: Ian Robinson
 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Problem with CommandButton (DotNetNuke.UI.WebControls)Problem with CommandButton (DotNetNuke.UI.WebControls)


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out