Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7703111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:23:02+00:00 2026-05-31T23:23:02+00:00

I have a button on an aspx page that is supposed to send an

  • 0

I have a button on an aspx page that is supposed to send an email… my code appears to be setup correctly but when the button is clicked, nothing happens. Here is the code. It is intended to display an alert then redirect to the success page but nothing happens…

There is no onclick, but according to this, there shouldn’t be: http://www.velocityreviews.com/forums/t367616-using-handles-vb-vs-c.html Also the guide I got this code from doesn’t use onclick either, although it’s outdated.

The markup is:

<%@ Page Title="Sign Up" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="signup.aspx.cs" Inherits="WebApplication2._Default" %>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
    Email Service
</h2>

Re-enter your email address to confirm signup for updates. 
<br />
<table border="0">
<tr>
    <td><b>Email:</b></td>
    <td><asp:TextBox runat="server" ID="UsersEmail" Columns="30"></asp:TextBox></td>
</tr>
<tr>
    <td colspan="2" align="center">
        <asp:Button runat="server" ID="SendEmail" Text="Sign Up"/>
    </td>
</tr>
</table>

The code-behind is:

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

    }

    protected void SendEmail_Click(object sender, EventArgs e) //Handles SendEmail.Click
    {
        try
        {
            //!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
            string ToAddress = "info@removed.org";

            //(1) Create the MailMessage instance
            MailMessage mm = new MailMessage(UsersEmail.Text, ToAddress);

            //(2) Assign the MailMessage's properties

            mm.Subject = UsersEmail.Text + " would like to sign up for updates";
            mm.Body = "Hello, I would like to sign up for updates. My email is " + UsersEmail.Text + ". Thank you.";
            mm.IsBodyHtml = false;

            //(3) Create the SmtpClient object
            SmtpClient smtp = new SmtpClient("[removed]");
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

            //(4) Send the MailMessage (will use the Web.config settings)
            smtp.Send(mm);
        }
        catch (Exception ex)
        {
            string strError = "<Script language=javascript>alert('Error');</Script>";
            Response.Write(strError);
            Response.Redirect("Success.aspx");

        }

        string strMsg = "<Script language=javascript>alert('Emailsent');</Script>";
        Response.Write(strMsg);
        Response.Redirect("Success.aspx");

        //System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert(""Hello this is an Alert"")</SCRIPT>");
    }

}

}

I really doubt onclick is the solution anyway, because that not process any code..

Any ideas? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:23:03+00:00Added an answer on May 31, 2026 at 11:23 pm

    Add the handler to the event

    <asp:Button runat="server" ID="SendEmail" Text="Sign Up" OnClick="SendEmail_Click"/>
    

    Next:

    If you do this:

    catch (Exception ex)
            {
                string strError = "<Script language=javascript>alert('Error');</Script>";
                Response.Write(strError);
                Response.Redirect("Success.aspx");
    
            }
    

    You won’t know anything about the error, for the first reason because a Redirect is made so the javascript code won’t get the chance to run and the next reason is that catching the exception like this, doing nothing with it, you’ll loose the instructions how to fix it.

    You don’t need to set the handler in markup, if you think it bloats it. You can do it for sure in code

    public class _Default : System.Web.Page
    
    {
        public _Default()
        {
             this.Init += (_o, _e) =>
              {
                  SendEmail.Click += SendEmail_Click;
              };
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an aspx page that contains a checkbox, and a button. The button
I have an aspx page that on a button click creates a BackgroundWorker and
I have a button on a web page that when clicked connects to my
On an ASPX.Page, I have a button that performs a postback. User must be
I have an ASPX page with two RequiredFieldValidator and a button to go to
I have an aspx page with multiple FileUpload controls and one Upload button. In
I have a simple aspx page with a few TextBoxes and a submit button.
How to insert an event to the aspx.cs page. I have one asp:button and
I have a custom control in an aspx page that has a property named
I am trying to set a default button in my ASPX page. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.