繁体   English   中英

打开弹出窗口时不触发按钮单击事件

[英]button click event is not fired when pop up is opened

我正在aspx网站上工作,需要弹出一个窗口。 我有一个弹出窗口,我想在网站上使用它。 我的问题是当我在imagebutton中使用pop时,会弹出而不是button_click事件不会触发。 我只希望我的弹出窗口可以打开,并且按钮单击事件也可以正确触发。 请帮助我。 我的JavaScript很弱。 我的代码在这里:

Asp.Net代码:-

         <script type="text/javascript">
               $("[id*=ImageButton1]").live("click", function () {
                   $("#modal_dialog").dialog({
                       buttons: {
                           Close: function () {
                               $(this).dialog('close');
                           }
                       },
                       modal: true
                   });
                   return false;
               });
</script>

                <asp:ImageButton ID="ImageButton1" style="margin-left:7px;" ImageUrl="~/button.png"  runat="server" 
                    onclick="ImageButton1_Click"></asp:ImageButton>

我的C#代码在这里:

            protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LPSConnection"].ConnectionString.ToString());
    con.Open();
    int id = Int32.Parse(Request.QueryString["id"].ToString());
    SqlDataReader rd = new SqlCommand("Select Booked from ExpertChat where id=" + id, con).ExecuteReader();
    rd.Read();

    int x = Int32.Parse(rd["Booked"].ToString());
    rd.Close();
    if (x == 0)
    {
        SqlCommand cmd = new SqlCommand("Update ExpertChat set Booked=1 where id=" + id, con);
        cmd.ExecuteNonQuery();
        SqlCommand mRead1 = new SqlCommand("insert into chat (ExpertName,UserName,rate) Values ('" + Label1.Text + "','" + Session["SName"] + "','" + Label5.Text + "')", con);
        mRead1.ExecuteNonQuery();
        SqlDataReader mRead4;
        mRead4 = new SqlCommand("Select top 1 id from Chat where ExpertName='" + Label1.Text + "' order by id Desc", con).ExecuteReader();
        mRead4.Read();
        int x1;
        x1 = Int32.Parse(mRead4["id"].ToString());
        mRead4.Close();

        wait(x1);
    }
    else
    {
        Response.Redirect("ExpertMail.aspx?id=" + id);

    }

}

我提供了一个完整的工作示例。 首先,您至少需要一个服务器(回发)控件,以便渲染引擎包括__doPostBack方法。 在关闭对话框时,您调用回发以便调用服务器方法。

ASPX

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SimplePage.aspx.cs" Inherits="DeleteMeEgal.SimplePage"%>

<html>
<head runat="server">
    <title></title>
</head>
<body>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.0.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.js"></script>

    <form id="form1" runat="server">
    <div>

    Button: 
    <asp:ImageButton ClientIDMode="Static" ID="ImageButton1" 
            ImageUrl="http://www.heise.de/icons/ho/heise_online_lupe.gif"  runat="server" 
            onclick="ImageButton1_Click1"></asp:ImageButton>


 <script type="text/javascript">
     $(document).ready(function () {
         $('#ImageButton1').click(function () {
             $("#dialog").dialog(
                    {
                        buttons: {
                            Close: function () {
                                $(this).dialog('close');
                                __doPostBack('ImageButton1', '');
                            }
                        },
                        modal: true
                    });
             return false;
         });
     });
</script>
    </div>

    <div style="visibility: hidden">
        <div id="dialog" title="Basic dialog" >
          <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
        </div>
    </div>

    <%-- included to force __doPostBack javascript function to be rendered --%>
    <asp:LinkButton ID="LinkButton1" runat="server" /> 

    </form>
</body>
</html>

背后的代码:

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

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

        }

        protected void ImageButton1_Click1(object sender, ImageClickEventArgs e)
        {
            Response.Write("You ran the ImageButton1_Click click event");
        }

    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM