Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Vishnu Kiran 3 posts 23 karma points
    Nov 16, 2009 @ 08:40
    Vishnu Kiran
    0

    .Net user control button click events not working

    Hi All,

        I created a new .net user control in .net framework 2.0 and tried to access the same from the CMS by creating the macros. I am able to import into the same into the RUNAWAY module. 

         The page_load event of the user control is working fine and i placed an button in the user control and written the code to change the text of an literal when the button is clicked.

        The button click event is not getting executed in the CMS pages.

        Waiting for the responses.

     

    Thanks,
    Vishnu

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Nov 16, 2009 @ 09:43
    Richard Soeteman
    0

    Hi this should work in your usercontrol also. Did you assign the event handler? If so, set a breakpoint in the button click event handler code and attach the debugger in visual studio to see what happens.

    Cheers,

    Richard

  • Vishnu Kiran 3 posts 23 karma points
    Nov 16, 2009 @ 11:10
    Vishnu Kiran
    0

    Hi

    I created the user control in the visual studio IDE and placed the same in the aspx page in the same solution and it is working perfect in that.The same if i copy into the CME, button click event is not getting fired.

    Thanks,
    Vishnu

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Nov 16, 2009 @ 16:32
    Richard Soeteman
    0

    I'm curious how you wired up the event handlers, It shouldn't make any difference. Can you post the ascx and code behind code?

    Cheers,

    Richard

  • Vishnu Kiran 3 posts 23 karma points
    Nov 17, 2009 @ 06:24
    Vishnu Kiran
    0

    Hi Richard,

    Thanks for the reply.

    I am hereby sending the code which i have used.

    Thanks,
    Vishnu

    -------------------------------------------------------------------------------------

    UCSample1.ascx

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UCSample1.ascx.cs" Inherits="UCSample2.UCSample1" %>
    Hello World 2<p>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </p>
    <p>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    </p>
    <p>
        <asp:Literal ID="Literal1" runat="server"></asp:Literal>
    </p>

    UCSample1.ascx.cs

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace UCSample2
    {
        public partial class UCSample1 : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    Literal1.Text = "test data page load";
                }
            }

            protected void Button1_Click(object sender, EventArgs e)
            {
                Literal1.Text = "You entered : " + TextBox1.Text;
            }
        }
    }

    Default.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="UCSample2._Default" %>

    <%@ Register src="UCSample1.ascx" tagname="UCSample1" tagprefix="uc1" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
       
            <uc1:UCSample1 ID="UCSample11" runat="server" />
       
        </div>
        </form>
    </body>
    </html>

    Default.aspx.cs

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace UCSample2
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {

            }
        }
    }

  • Steve D 11 posts 41 karma points
    Feb 04, 2010 @ 23:46
    Steve D
    0

    I am having almost exactly the same problem. The button click does not seem to be causing a postback (therefore the debugger does not fire). This is happening for two user controls on my content page. My code is almost identical to the code listed here.

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Feb 05, 2010 @ 06:10
    Richard Soeteman
    0

    I find this very strange never experienced this.  If you set a breakpoint at page_load, that gets hit? even after postback? Also try to load the page with queryparameter ?umbdebugshowtrace=true to see if you have any errors on the page.

    Cheers,

    Richard

  • tarekahf 215 posts 153 karma points
    May 03, 2010 @ 22:05
    tarekahf
    0

    I faced similar problem. See this http://bit.ly/bPfxG8 for complete details. The link button if used under Umbraco will case ASP.NET event model to misbehave.

    Tarek.

  • Kanwar 8 posts 29 karma points
    Jul 28, 2011 @ 20:32
    Kanwar
    0

    Hello all,

    I am getting same problem.User control .ascx contain one texbox and one button control.Validation is working fine but click event is not working.

     

    Ajay Kanwar

  • Waylon Martinez 12 posts 37 karma points
    Jul 29, 2011 @ 02:11
    Waylon Martinez
    0

    Do you have example of your code syntax?

     

    You want to make sure that you are not altering the code on "postback".

     

  • Kanwar 8 posts 29 karma points
    Jul 29, 2011 @ 05:43
    Kanwar
    0

    Dear my code in .ascx page is:


     <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MKFANewLetterHome.ascx.cs" Inherits="NewsLetterHome.MKFANewLetterHome" %>
     
             <script type="text/javascript">

                 $(document).ready(function () {

                     $('#<%=txtEmail.ClientID %>').watermark('Email Address', { className: 'watermark' });

                 });
                
                
                 $('#<%=txtEmail.ClientID %>').mousedown(function () {

                 $.watermark.hide($('#<%=txtEmail.ClientID %>'));

        });

               

            </script>

          <style type="text/css">

                .watermark
                {

                    color: #999;

                  }
                  .redqired
                  {
                      color:red;
                  }

             </style>
    <div class="newsLetterDetails">
                     <span id="newsLetterEmail" style="float:left;margin-top:8px" >  
                        <asp:TextBox ID="txtEmail" runat="server"
                            Width="150px" CssClass="newsLetterEmail watermark"
                         ValidationGroup="News"></asp:TextBox>
                     <asp:RequiredFieldValidator
                                ID="rfvEmail" runat="server" ErrorMessage="Email"
                         ControlToValidate="txtEmail" ValidationGroup="News"><span class="redqired">*</span></asp:RequiredFieldValidator>
                         <asp:RegularExpressionValidator ID="rgvEmail" runat="server"
                         ErrorMessage="Email Address only" ControlToValidate="txtEmail" 
                         ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                         ValidationGroup="News"><span class="redqired">*</span></asp:RegularExpressionValidator>
                         <asp:Label ID="lblMesageEmail" runat="server" Text="" Visible="False"></asp:Label>
                            </span>
                       <span id="newsLetterGo" style="float:left;margin-top:8px">
                         <asp:ImageButton ID="imgNewsLetter" runat="server"
                            ImageUrl="../umbraco/images/Media/NewsLatter.png"
                         CssClass="imgNewsLatter" onclick="imgNewsLetter_Click"
                         ValidationGroup="News" /> </span></br>
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" CssClass="redqired"
                         ValidationGroup="News" />
                       
                    </div>

    -------------------------------------------------------------------------------------------------------------------------------------------------------

     

     

    and .cs is:

     

     

     

    private string EmailAddress;

            public string _EmailAddress

            {

                get;

                set;

            }

            protected void Page_Load(object sender, EventArgs e)

            {

     

            }

            private static SqlConnection GetConnection()

            {

                SqlConnection oConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Con"].ConnectionString);

                return oConnection;

            }

            protected int SendMailToMKFencing(string newLetterName)

            {

               

                        MailMessage mailMessage = new MailMessage();

                        mailMessage.From = new MailAddress("UserId");

                        mailMessage.To.Add("UserId");

                        mailMessage.Bcc.Add(_EmailAddress.Trim());

                        mailMessage.Subject ="News Letter";

                        Attachment attachNewsLetter = new Attachment(Server.MapPath("/umbraco/images/UploadNewsLetter/" + newLetterName.Trim()));

                        mailMessage.Attachments.Add(attachNewsLetter);

                        mailMessage.Body ="Body Message";

                      //  mailMessage.IsBodyHtml = true;

                        SmtpClient smtpClient = new SmtpClient();

                        smtpClient.UseDefaultCredentials = true;

                        smtpClient.Credentials = new System.Net.NetworkCredential("UserID", "password");

                        int mailStatus = 0;

                        try

                        {

                            smtpClient.Send(mailMessage);

                            mailStatus = 1;//Mail send

                        }

                        catch (Exception err)

                        {

                            throw err;

                            mailStatus = 0;

                        }

                        finally

                        {

                            mailMessage = null;

                            smtpClient = null;

                        }

                 return mailStatus;

     

            }

            protected void imgNewsLetter_Click(object sender, ImageClickEventArgs e)

            {

                if (txtEmail.Text != "")

                {

                    _EmailAddress = txtEmail.Text.Trim();

                    SqlConnection oConnection = GetConnection();

                    SqlCommand oCommand = new SqlCommand();

                    oCommand.Connection = oConnection;

                    oCommand.CommandType = CommandType.StoredProcedure;

                    oCommand.CommandText = "sp_Name";

                    oCommand.Parameters.AddWithValue("@Email", _EmailAddress);

                    string newLetterName = "";

                    try

                    {

                        oConnection.Open();

                        newLetterName = Convert.ToString(oCommand.ExecuteScalar());

                    }

                    catch (Exception err)

                    {

                        throw err;

                    }

                    finally

                    {

                        oConnection.Close();

                        oConnection.Dispose();

                        oCommand.Dispose();

                    }

                    if (newLetterName.Trim() == "00")

                    {

                        txtEmail.Visible = false;

                        lblMesageEmail.Visible = true;

                        imgNewsLetter.Visible = false;

                        lblMesageEmail.Text = "Our team contact you.";

                    }

                    else if (newLetterName.Trim() == "")

                    {

                        Response.Redirect("/1187", false);

                    }

                    else

                    {

                        int mailClientStatus = SendMailToMKFencing(newLetterName);

                        if (mailClientStatus == 1)

                        {

                            lblMesageEmail.Text = "News letter has been sucessfully sent!";

                            txtEmail.Visible = false;

                            lblMesageEmail.Visible = true;

                            imgNewsLetter.Visible = false;

                            txtEmail.Text = "";

                        }

     

                    }

                }

            }

     

    This code is working fine in mozila and google crome.Butit's not working in IE any version or Opera.

     

  • Kanwar 8 posts 29 karma points
    Aug 01, 2011 @ 06:55
    Kanwar
    0

    please help me any one. My code is above and button click event is not working in IE and opera.It's working fine in Mozila and google crome.It's working fine in all browser's before it create micro and attach it to my application.

  • Owen 123 posts 246 karma points
    Aug 01, 2011 @ 07:09
    Owen
    0

    where is your code?

  • Kanwar 8 posts 29 karma points
    Aug 01, 2011 @ 07:22
    Kanwar
    0

    thanks for response,In page 1

  • Kanwar 8 posts 29 karma points
    Sep 06, 2011 @ 07:13
    Kanwar
    0

    Please help me any one.I am still in problem.

  • Jon Boyer 37 posts 59 karma points
    Sep 19, 2011 @ 05:15
    Jon Boyer
    0

    Don't forget to put your form inside a <form runat="server"> </form> pair of tags or you won't trigger a postback properly.

  • Eric Herlitz 97 posts 129 karma points
    Sep 30, 2011 @ 23:15
    Eric Herlitz
    0

     

    This can be solved by disabling any control using PostBackUrl since they mess with postbacks in general in Umbraco

    Simply search your project for any references to PostBackUrl and disable them, they are a no use in umbraco.

     

  • David Greasley 4 posts 71 karma points c-trib
    Mar 29, 2012 @ 13:12
    David Greasley
    0

    I am having the exact same problem. I have a usercontrol with a button on that I have subscribed to the onClick event of. The user control works fine in a normal asp.net page. When placed in an umbraco page the page_load event fires but not the button onClick event.

    There are no asp errors shown on the page. There are no errors shown when using the umbDebugShowTrace=true option. Everything is encapsulated within a single <form runat="server"> tag.

    I have tried the user control in a blank umbraco page with a blank template to ensure there are no issues created by my template.

    Does anyone have any ideas as to why this would be?

  • Joel 7 posts 27 karma points
    Apr 07, 2015 @ 18:43
    Joel
    0

    I'm having the same problem. I just have a textbox and button and a literal. When you click the button it just sets the literal to the text in the texbox, but when I run it in umbraco the button doesn't cause a post back. Did anyone ever figure out how to make this work?

Please Sign in or register to post replies

Write your reply to:

Draft