【问题标题】:.net click on image button not working in Internet Explorer but in Firefox.net 单击图像按钮在 Internet Explorer 但在 Firefox 中不起作用
【发布时间】:2008-11-18 10:14:53
【问题描述】:

我已经为 ascx 编写了 C# 代码。我正在尝试通过单击图像按钮发送电子邮件,该按钮在 Mozilla Firefox 中有效,但在 Internet Explorer 中无效。

这个函数在按钮点击时被调用:

<%@ 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 = "manoj.singh@espireinfo.com";
            string to = "manoj.singh@espireinfo.com";
            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 // error
            {
                Response.Write(error);
            }
        }
    }
</script>

标记:

<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>

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    在后面的代码中改变 protected void btnSubmit_Click(object sender, EventArgs e)

    与 protected void btnSubmit_Click(object sender, ImageClickEventArgs e)

    【讨论】:

      【解决方案2】:

      大家好,

      此代码在 IE 而非 mozilla 中运行,任何人都可以给出想法

      document.onkeypress = KeyCheck; 函数 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";
                  }
      
              }
          }
      

      【讨论】:

        【解决方案3】:

        您为什么使用 ImageButton ... 为什么不使用常规按钮,并使用 CSS 更改背景。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-10-19
          • 1970-01-01
          • 1970-01-01
          • 2014-02-01
          • 2012-12-11
          • 1970-01-01
          相关资源
          最近更新 更多