这是LinkButton,它会打开一个弹出窗口。
<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容器中的所有Label(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,他读取标签。因此,如果用户单击LinkButton(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);
}
答案 0 :(得分:0)
在ASP.NET WebForms中,每个页面都有一个form
,客户端发出的通信通常是通过发布form
来完成的。服务器接收所有内容,但作为响应发送的页面不会在当前代码中打开弹出窗口。您可以像ScriptManager.RegisterStartupScript
那样在btnEdit_Click
拨打libKlient_Click
来实现您的目标。
或者,您可以添加CssClass
值,也可以编辑到TextBox
控件并将按钮更改为此类
<asp:Button Text="Edit" ID="btnEdit" OnClientClick="enableEditable(); return false;" runat="server" />
其中enableEditable
是
function enableEditable() {
$(".editable").removeAttr("disabled");
}