【问题标题】:Editmode in jquery popup does not workjQuery弹出窗口中的Editmode不起作用
【发布时间】:2017-03-22 09:07:44
【问题描述】:

这是 LinkBut​​ton,它会打开一个弹出窗口。

<asp:LinkButton ID="libKlient" OnClick="libKlient_Click" runat="server" /></td>

我有这个 jquery 弹出窗口:

<script type="text/javascript" src="scripts/jquery.min.js"></script>
    <script src="scripts/jquery-ui.js" type="text/javascript"></script>
    <link href="scripts/jquery-ui.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function pop() {
            $("#dialog").dialog({
                title: "Klient",
                buttons: {
                    Close: function () {
                        $(this).dialog('close');
                    }
                }
            });
            return false;
        };
    </script>

这里是 div Container (ID=Dialog) 中的所有标签:

 <div id="dialog" style="display: none;">
        <asp:Panel ID="pnlDialog" runat="server">
            <h1>Klient
            </h1>
            <table>

                <tr>
                    <td>Name:</td>
                    <td>
                        <asp:TextBox ID="txtName" runat="server" /></td>
                </tr>
                <tr>
                    <td>Adress:</td>
                    <td>
                        <asp:TextBox ReadOnly="true" ID="txtAdress" runat="server" /></td>
                </tr>
 <tr>
                    <td>Phone:</td>
                    <td>
                        <asp:TextBox ReadOnly="true" ID="txtPhone" runat="server" /></td>
                </tr>
 <tr>
                    <td>Email:</td>
                    <td>
                        <asp:TextBox ReadOnly="true" ID="txtEmail" runat="server" /></td>
                </tr>
 <tr>
                    <td>Birtday:</td>
                    <td>
                        <asp:TextBox ReadOnly="true" ID="txtBirtday" runat="server" /></td>
                </tr>
            </table>

        
        <asp:Button Text="Edit" ID="btnEdit" OnClick="btnEdit_Click" runat="server" />
    </asp:Panel></div>

这里是读取标签的 Sqldatereader。因此,如果用户单击 LinkBut​​ton(libKlient) 弹出窗口并且所有文本框都启用 = false。直到这里一切正常!

protected void libKlient_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterStartupScript(this, GetType(), "Show Modal Popup", "pop();", true);

        string sql = "Select * From Klient WHERE Name=@Name";
        using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString))
        {
            using (SqlCommand cmd = new SqlCommand(sql, con))
            {
                con.Open();
                cmd.Connection = con;
                cmd.Parameters.AddWithValue("@Name", GridView1.SelectedDataKey.Values[3].ToString());

                using (SqlDataReader r = cmd.ExecuteReader())
                {
                    while (r.Read())
                    {
                        try
                        {

                            txtName.Text = r["Name"].ToString();
                            txtName.Enabled = false;

                            txtAdress.Text = r["Adress"].ToString();
                            txtAdress.Enabled = false;

 	            txtPhone.Text = r["Phone"].ToString();
                            txtPhone.Enabled = false;

                            txtEmail.Text = r["Email"].ToString();
                            txtEmail.Enabled = false;

         	            txtBirtday.Text = r["Birtday"].ToString();
                            txtBirtday.Enabled = false;

                        }
                        catch (Exception ex)
                        {
                        }

                    }
                }
            }
            con.Close();
        }


    }

问题在于编辑按钮 (ID= btnEdit)。我希望如果我单击按钮,所有文本框都将从启用的 false = 启用的 true 中获取。但它不起作用。一旦我单击编辑按钮,弹出窗口就会关闭:

protected void Read(Control control)
    {
        foreach (Control c in control.Controls)
        {
            if (c is TextBox && c.ID.StartsWith("txt"))
                ((TextBox)c).Enabled = true;
        }
    }

    protected void btnEdit_Click(object sender, EventArgs e)
    {
        Read(pnlDialog);
    
    }

【问题讨论】:

    标签: javascript c# jquery popup edit


    【解决方案1】:

    在 ASP.NET WebForms 中,每个页面都有一个form,客户端发出的通信通常通过发布该form 来完成。服务器接收所有内容,但作为响应发送的页面不会在您当前的代码中打开弹出窗口。你可以通过btnEdit_Click 调用ScriptManager.RegisterStartupScript 来实现你想要的,就像你已经在libKlient_Click 所做的那样。

    或者,您可以添加一个 CssClass 值,也许可以编辑到您的 TextBox 控件并将您的按钮更改为类似这样的内容

    <asp:Button Text="Edit" ID="btnEdit" OnClientClick="enableEditable(); return false;" runat="server" />
    

    enableEditable 在哪里

    function enableEditable() {
        $(".editable").removeAttr("disabled");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-22
      • 2023-03-18
      • 2020-12-06
      • 1970-01-01
      相关资源
      最近更新 更多