tags:

views:

1523

answers:

5

Hi,

I have written c# code for ascx. I am trying to send an email on the click of image button. Please see the code below.

Here is the codebehind function which is called on submit button click.

<%@ Control Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Globalization" %>

<script language="c#" runat="server">

protected void btnSubmit_Click(object sender, EventArgs e)
{
        if (Page.IsValid)
        {
            string from = "[email protected]";
            string to = "[email protected]";
            string subject = "Keep me Updated";
            string sendguide = "";

            if (optsendguide.Checked)
            {
                sendguide = "Yes Please send me";

            }
            else
            {
                sendguide = "No Please don't send me";
            }

            // build up the body text
            string body = "<html><body>";
            body += String.Format("<div>Title: {0} </div>", title.Text);
            body += String.Format("<div>First Name: {0} </div>",firstname.Value);
            body += String.Format("<div>Sur Name: {0} </div>", surname.Value);
            body += String.Format("<div>Email address: {0} </div>", email.Value);
            body += String.Format("<div>Break Type: {0} </div>", breakTypeDescription.Text);
            body += String.Format("<div>Big weekends guide: {0} </div>", sendguide);
            body += "</body></html>";

            string error = Utilities.SendEmail(to, from, subject, body);
            if (error == "")
            {
                // success
                Response.Redirect("index.aspx");
            }
            else
            {
                //fail
                Response.Write(error);
            }
        }

    }
 </script>

and below is the inline coding for Image Button click event

<div class="form_elm_button">
    <asp:ImageButton ID="SubmitButton" runat="server" Text="Submit" ImageUrl="/images/17-6164button_submit.png" OnClick="btnSubmit_Click" CausesValidation="true"/>
</div>

Surprising its all working fine in Firefox but not working for internet explorer.

Please help!

Thanks. Manoj

A: 

It would help a lot if you formatted the code as code...

Tor Haugen
Hi How could I format the code.
MKS
I've done it for you. In future, look at the button next to the quote button above the edit box.
OJ
+1  A: 

In code behind just change protected void btnSubmit_Click(object sender, EventArgs e)

with protected void btnSubmit_Click(object sender, ImageClickEventArgs e)

A: 

Why are you using an ImageButton ... why not just use a regular button, and change the background with CSS.

Martin
A: 

I got the same problem, anybody got a solution?

A: 

hai all,

This code is working in IE not mozilla,anyone give idea

document.onkeypress = KeyCheck; function KeyCheck(e) {

        var KeyID = (window.event) ? event.keyCode : e.keyCode;
        if (KeyID == 0) {
            var image = document.getElementById("<%= imagetirukural.ClientID%>");
            var label = document.getElementById("<%= lbltirukural.ClientID%>");
            if (image != null) {

                document.getElementById("<%= imagetirukural.ClientID%>").style.display = "block";
                InitializeTimer();
            }
            else {
                document.getElementById("<%= lbltirukural.ClientID%>").style.display = "block";
                InitializeTimer();
            }
        }
        else if (KeyID != 0) {


            if (image != null) {
                document.getElementById("<%= imagetirukural.ClientID%>").style.display = "block";
            }
            else {
                document.getElementById("<%= lbltirukural.ClientID%>").style.display = "block";
            }

        }
    }
subha