1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Button Click Event Does Not Fire

Button Click Event Does Not Fire

6 posts, 0 answered
  1. Allan
    Allan avatar
    3 posts
    Registered:
    10 Jun 2009
    25 May 2010
    Link to this post
    Hi,

    I built a User Control with a button, but the click or page load events do not fire when the button is pressed.

    Thanks,

    Al

    Markup:

    <%

    @ Control Language="C#" AutoEventWireup="true" CodeFile="GlobalRegionalEmail.ascx.cs" Inherits="UserControls_GlobalRegionalEmail" %>

     

    <

     

    asp:Label ID="lblRegion" runat="server">Region:</asp:Label>

     

    <

     

    asp:DropDownList ID="ddlRegion" runat="server" />

     

    <

     

    asp:CompareValidator ID="cvRegion" runat="server"

     

     

    ErrorMessage="Must select a region" ControlToValidate="ddlRegion"

     

     

    ValueToCompare="0" Operator="NotEqual" Display="Dynamic"/>

     

    <

     

    br />

     

    <

     

    br />

     

    <

     

    asp:Label ID="lblSubject" runat="server">Subject:</asp:Label>

     

    <

     

    asp:TextBox ID="txtSubject" runat="server" Width="400px" />

     

    <

     

    asp:RequiredFieldValidator ID="rfvSubject" runat="server"

     

     

    ControlToValidate="txtSubject" ErrorMessage="Must Enter subject" />

     

    <

     

    br />

     

    <

     

    br />

     

    <

     

    asp:Label ID="lblBody" runat="server">Body:</asp:Label>

     

    <

     

    br />

     

    <

     

    asp:TextBox ID="txtBody" TextMode="MultiLine" runat="server" Height="300px" Width="90%" />

     

    <

     

    asp:RequiredFieldValidator ID="rfvBody" runat="server"

     

     

    ControlToValidate="txtBody" ErrorMessage="Must Enter body" />

     

    <

     

    br />

     

    <

     

    br />

     

    <

     

    asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" CausesValidation="true" />

     



    Code Behind:

    public

     

    partial class UserControls_GlobalRegionalEmail : System.Web.UI.UserControl

     

    {

     

    protected void Page_Load(object sender, EventArgs e)

     

    {

     

    if (!IsPostBack)

     

    {

     

    //load regions

     

    ddlRegion.DataTextField =

    "Name";

     

    ddlRegion.DataValueField =

    "Value";

     

    ddlRegion.DataSource =

    DataAccess.GetRegions();

     

    ddlRegion.DataBind();

    ddlRegion.Items.Insert(0,

    new ListItem("", "0")); //add prompt

     

    }

    }

     

    protected void btnSubmit_Click(object sender, EventArgs e)

     

    {

     

    if (Page.IsValid == true)

     

    {

     

    //get logged in user email

     

     

    string email = DataAccess.GetUser(Page.User.Identity.Name).Email;

     

     

    //todo email in service (Gets list of users per region from db and sends email)

     

     

    //RegionalEmail(

     

     

    // ddlRegion.SelectedIndex,

     

     

    // email,

     

     

    // txtSubject.Text,

     

     

    // txtBody.Text);

     

    }

    }

    }

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    26 May 2010
    Link to this post
    Hi Allan,

    Could you try to subscribe for Click event in Page_Load instead of doing this in the control template. Let us know how it goes.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Allan
    Allan avatar
    3 posts
    Registered:
    10 Jun 2009
    26 May 2010
    Link to this post
    Ivan,

    I tried the event declaration in Page_Load but experience the same results.  I am using SItefinity 3.6.

    Thanks,

    Al

     

    01.using System;
    02.using System.Data;
    03.using System.Configuration;
    04.using System.Collections;
    05.using System.Web;
    06.using System.Web.Security;
    07.using System.Web.UI;
    08.using System.Web.UI.WebControls;
    09.using System.Web.UI.WebControls.WebParts;
    10.using System.Web.UI.HtmlControls;
    11.  
    12.public partial class UserControls_GlobalRegionalEmail : System.Web.UI.UserControl
    13.{
    14.    protected void Page_Load(object sender, EventArgs e)
    15.    {
    16.        if (!IsPostBack)
    17.        {
    18.            //load regions
    19.            ddlRegion.DataTextField = "Name";
    20.            ddlRegion.DataValueField = "Value";
    21.            ddlRegion.DataSource = DataAccess.GetRegions();
    22.            ddlRegion.DataBind();
    23.  
    24.            ddlRegion.Items.Insert(0, new ListItem("", "0"));    //add prompt
    25.  
    26.            btnSubmit.Click +=new EventHandler(btnSubmit_Click);
    27.        }
    28.    }
    29.    protected void btnSubmit_Click(object sender, EventArgs e)
    30.    {
    31.        if (Page.IsValid == true)
    32.        {
    33.            //get logged in user email
    34.            string email = DataAccess.GetUser(Page.User.Identity.Name).Email;
    35.  
    36.            //todo email in service (Gets list of users per region from db and sends email)
    37.            //RegionalEmail(
    38.            //    ddlRegion.SelectedIndex,
    39.            //    email,
    40.            //    txtSubject.Text,
    41.            //    txtBody.Text);
    42.        }
    43.    }
    44.}

    01.<%@ Control Language="C#" AutoEventWireup="true" CodeFile="GlobalRegionalEmail.ascx.cs" Inherits="UserControls_GlobalRegionalEmail" %>
    02.<asp:Label ID="lblRegion" runat="server">Region:</asp:Label>
    03.<asp:DropDownList ID="ddlRegion" runat="server" />
    04.<asp:CompareValidator ID="cvRegion" runat="server"
    05.    ErrorMessage="Must select a region" ControlToValidate="ddlRegion"
    06.    ValueToCompare="0" Operator="NotEqual" Display="Dynamic"/>
    07.<br />
    08.<br />
    09.<asp:Label ID="lblSubject" runat="server">Subject:</asp:Label>
    10.<asp:TextBox ID="txtSubject" runat="server" Width="400px" />
    11.<asp:RequiredFieldValidator ID="rfvSubject" runat="server" 
    12.    ControlToValidate="txtSubject" ErrorMessage="Must Enter subject" />
    13.<br />
    14.<br />
    15.<asp:Label ID="lblBody" runat="server">Body:</asp:Label>
    16.<br />
    17.<asp:TextBox ID="txtBody" TextMode="MultiLine" runat="server" Height="300px" Width="90%" />
    18.<asp:RequiredFieldValidator ID="rfvBody" runat="server" 
    19.    ControlToValidate="txtBody" ErrorMessage="Must Enter body" />
    20.<br />
    21.<br />
    22.<asp:Button ID="btnSubmit" runat="server" Text="Submit" CausesValidation="true" />
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    26 May 2010
    Link to this post
    Hello Allan,

    Could you try moving the event declaration out of the if page not post-back statement?

    Greetings,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Allan
    Allan avatar
    3 posts
    Registered:
    10 Jun 2009
    26 May 2010
    Link to this post
    Radoslav,

    I tried your suggestion, but I unfortunately have the same result.

    Thanks,

    Al Rosner

    protected void Page_Load(object sender, EventArgs e)
    {
        btnSubmit.Click += new EventHandler(btnSubmit_Click);
     
        if (!IsPostBack)
        {
            //load regions
            ddlRegion.DataTextField = "Name";
            ddlRegion.DataValueField = "Value";
            ddlRegion.DataSource = DataAccess.GetRegions();
            ddlRegion.DataBind();
     
            ddlRegion.Items.Insert(0, new ListItem("", "0"));    //add prompt
     
        }
    }
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    26 May 2010
    Link to this post
    Hello Allan,

    Attached is a sample control where the event fires. You can try this out in your Sitefinity project.

    All the best,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
6 posts, 0 answered