我在asp.Net中有一个网站,其中包含一个带有asp按钮的弹出窗口。我的问题是弹出窗口中没有触发按钮单击事件。当imagebutton1点击时,我的弹出窗口会打开。我也在使用计时器滴答。 我完全陷入其中。 我的代码如下: -
<div>
<script type="text/javascript">
function buttonClicked() {
var textBox = $get("TextBox1");
textBox.scrollTop = textBox.scrollHeight;
}
</script>
<asp:UpdatePanel ID="ChatUpdatePanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<div id="second1" runat="server" style="width:570px;height:100px;background-color:#e5f7f6;border:solid 2px #35b8b3;position:absolute;margin-left:5px;margin-top:5px;border-radius:5px;">
<span style="color:Blue;font-weight:bold;margin-left:180px;margin-top:20px;">Ringing Expert...Please Wait</span>
</div>
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" ReadOnly="True"
width="100%" style="resize:none;" Height="200px" AutoPostBack="False"
MaintainScrollPositionOnPostBack="True" >
</asp:TextBox>
</ContentTemplate>
<Triggers>
<%--<asp:AsyncPostBackTrigger ControlID="SendButton" EventName="Click" />--%>
<asp:AsyncPostBackTrigger ControlID="ChatTextTimer" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer runat="server" ID="ChatTextTimer" Interval="100"
ontick="ChatTextTimer_Tick" />
<asp:TextBox ID="NewMessageTextBox" DefaultButton="SendButton" Columns="50" runat="server" Height="25px"
Width="80%" style="margin-left: 0px;margin-top:5px;" Font-Size="Medium" />
<asp:Button ID="SendButton" Text="Send" runat="server" OnClick="SendButton_Click" Height="25px" style="margin-left:50px;" />
<a href="#" style="text-decoration:line;">Report Abuse</a>
<br />
<div style="width:100%;margin-top:10px;">
<asp:Image ID="Image3" runat="server" Width="70px" Height="50px" />
<div style="width:80%;height:50px;float:right;margin-right:30px;">
Status:<br />
<span style="color:Blue;font-weight:bold;font-size:large;">Not Charging</span>
<span style="float:right;font-weight:bold;font-size:medium;color:Blue;">$ <asp:Label ID="Label12" runat="server" style="font-weight:bold;font-size:medium;color:Blue;" Text="Label"></asp:Label> / Minute</span>
</div>
</div>
我的后端代码如下: -
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
second1.Visible = false;
if (Session["User"] != "User")
{
Response.Redirect("signin.aspx");
}
else
{
if (Int32.Parse(Label13.Text) < 20)
{
Response.Redirect("Payment.aspx");
}
else
{
if(Int32.Parse(Label14.Text)==0)
{
Response.Redirect("ExpertMail.aspx?id="+Int32.Parse(Request.QueryString["id"]));
}
else
{
string str1 = Label1.Text;
string str = "<script type='text/javascript'>$(function (){ $('#modal_dialog').dialog({title: 'Chat with Expert', modal: true }); return false; });</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", str, false);
Image3.ImageUrl = Label8.Text;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LPSConnection"].ConnectionString.ToString());
con.Open();
SqlDataReader rd = new SqlCommand("Select Booked from ExpertChat where id=" + Int32.Parse(Request.QueryString["id"]), con).ExecuteReader();
rd.Read();
int y = Int32.Parse(rd["Booked"].ToString());
rd.Close();
if (y == 0)
{
SqlDataReader mRead1, mRead3,mRead4;
mRead1 = new SqlCommand("insert into chat (ExpertName,UserName,rate) Values ('" + Label1.Text + "','" + Session["SName"] + "','" + Label5.Text + "')", con).ExecuteReader();
mRead1.Close();
mRead3 = new SqlCommand("Update ExpertChat Set Booked=1 where SName='" + Label1.Text + "'", con).ExecuteReader();
mRead3.Close();
second1.Visible = true;
con.Close();
}
con.Close();
}
}
}
}
public void wait(int x)
{
}
protected void ChatTextTimer_Tick(object sender, EventArgs e)
{
if (second1.Visible)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LPSConnection"].ConnectionString.ToString());
con.Open();
SqlDataReader mRead4 = new SqlCommand("Select top 1 id from Chat where ExpertName='" + Label1.Text + "' order by id desc", con).ExecuteReader();
mRead4.Read();
int z = Int32.Parse(mRead4["id"].ToString());
mRead4.Close();
SqlDataReader rd = new SqlCommand("Select IsApproved from Chat where id=" + z, con).ExecuteReader();
rd.Read();
string str = (rd["IsApproved"].ToString());
rd.Close();
if (str == "Approved")
{
second1.Visible = false;
}
else if (str == "canceled")
{
}
else
{
con.Close();
}
}
else
{
int x1 = 0;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LPSConnection"].ConnectionString.ToString());
con.Open();
SqlDataReader rd;
rd = new SqlCommand("Select UserInitial,Updated from Chat where id =" + Int32.Parse(Request.QueryString["id"].ToString()), con).ExecuteReader();
rd.Read();
string str;
int i;
str = rd["UserInitial"].ToString();
i = Int32.Parse(rd["Updated"].ToString());
rd.Close();
if (i == 1)
{
x1 = x1 + 1;
TextBox1.Text = TextBox1.Text + Environment.NewLine + str;
SqlCommand
cmd = new SqlCommand("Update Chat set Updated=0 where id=" + Int32.Parse(Request.QueryString["id"].ToString()), con);
cmd.ExecuteNonQuery();
}
ScriptManager.RegisterStartupScript(this, this.GetType(), "TextBox1slide", "buttonClicked();", true);
con.Close();
}
}
protected void SendButton_Click(object sender, EventArgs e)
{
//SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LPSConnection"].ConnectionString.ToString());
//con.Open();
string messageMask = "{0} : {2}";
string message = string.Format(messageMask, Session["SName"].ToString(), DateTime.Now.ToShortTimeString(), NewMessageTextBox.Text);
TextBox1.Text = TextBox1.Text + Environment.NewLine + message;
//SqlCommand cmd, cmd1;
//cmd = new SqlCommand("Update Chat set Data='" + message + "' where id=" + Int32.Parse(Request.QueryString["id"].ToString()), con);
//cmd.ExecuteNonQuery();
//cmd1 = new SqlCommand("Update Chat set Updated1=1 where id=" + Int32.Parse(Request.QueryString["id"].ToString()), con);
//cmd1.ExecuteNonQuery();
NewMessageTextBox.Text = "";
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myScript", "document.getElementById('" + NewMessageTextBox.ClientID + "').value = '';", true);
ScriptManager.RegisterStartupScript(this, this.GetType(), "TextBox1slide", "buttonClicked();", true);
}
答案 0 :(得分:1)
我已经解决了。 这是一个愚蠢的错误。只需将按钮的SubMitBehaviour属性设置为false ...