【发布时间】:2014-05-16 23:27:29
【问题描述】:
这是我的代码
ASPX 代码:
<asp:Button ID="Button4" runat="server" onclick="Button4_Click" Text="Insert" />
C#:
public void MsgBox(String MessageToDisplay)
{
Label lblForMsg = new Label();
lblForMsg.Text = "<script language='javascript'>window.alert('" + MessageToDisplay + "')</script>";
Page.Controls.Add(lblForMsg);
}
protected void Button4_Click(object sender, EventArgs e)
{
SqlCommand com = new SqlCommand("insert into employe values(@id,@pass)", con);
SqlParameter obj1 = new SqlParameter("@Id", DbType.StringFixedLength);
obj1.Value = TextBox4.Text;
com.Parameters.Add(obj1);
SqlParameter obj2 = new SqlParameter("@pass", DbType.StringFixedLength);
obj2.Value = TextBox5.Text;
com.Parameters.Add(obj2);
com.ExecuteNonQuery();
con.Close();
MsgBox("Account Created");
if (Session["regis"] == null)
{
Response.Redirect("Profile.aspx");
}
else
{
Response.Redirect("Login.aspx");
}
}
我希望当我点击 button4 时,msgbox 显示,然后当我点击 msgbox 上的 ok 时,它会检查条件和对页面的响应。
我正在使用 Visual Studio 2010,asp.net/c#
【问题讨论】:
-
您调用 MsgBox 但随后您重定向到其他页面。用户的浏览器只会转到另一个页面,而不会看到该消息。
-
@JBrooks 是的,你说得对
标签: c# javascript asp.net