Small width layout Medium width layout Maximum width layout Small text Medium text Large text
     Search
Downloads Downloads Directory Directory Forums Forums Forge Forge Blogs Blogs        Marketplace Marketplace Careers Program Careers
Community › Forums Register  |  

AppTheory specializes in solutions based on the DotNetNuke platform and has 2 employees on the DotNetNuke Core Team.
  Ads  
Aspose - The .NET & Java component publisher
 


  Sponsors  

Meet Our Sponsors

Salaro -- Skins and more
OnyakTech
CrystalTech Web Hosting™
Webhost4life, specialists in DNN hosting
Mad Development is a full service interactive agency focusing on the merge of design, technology, e-commerce, and affiliate marketing by providing total website solutions.
SteadyRain
 


DotNetNuke Forums
 
  Forum  General DotNetN...  Extend It! (Pro...  Problem with CommandButton (DotNetNuke.UI.WebControls)
Previous Previous
 
Next Next
New Post 7/27/2008 1:48 AM
User is offline Michael Tobisch
36 posts
www.helferlein.com
10th Ranked


Problem with CommandButton (DotNetNuke.UI.WebControls) 

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

 
New Post 7/27/2008 11:48 AM
User is offline Ian Robinson
651 posts
www.engagesoftware.com
7th Ranked


Re: Problem with CommandButton (DotNetNuke.UI.WebControls) 

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


Ian Robinson
Engage Software
St. Louis, MO
314.966.4000



The leading provider of DotNetNuke support, training and custom development.
 
Previous Previous
 
Next Next
  Forum  General DotNetN...  Extend It! (Pro...  Problem with CommandButton (DotNetNuke.UI.WebControls)
 


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, 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 DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

 


Faculty of Graduate and Postdoctoral Studies
At the graduate level, the University of Ottawa offers more than 180 graduate certificates, master's degrees and PhDs, as well as interdisciplinary programs such as Women's Studies and Canadian Studies. Many postdoctoral opportunities are available in both the sciences and the humanities. For further information, please consult the site of the Faculty of Graduate and Postdoctoral Studies.
www.grad.uottawa.ca
Vekkin Solutions
Vekkin Solutions provides complete website solutions and custom module development to churches and small businesses.
www.vekkin.com
Powered by Adcuent®.Com
Adcuent® Consulting & Technology offers custom development web applications and hosting projects under the brand of Powered by Adcuent®.Com
www.adcuent.com

DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation
Hosted by MaximumASP