C# Response.Write和 Response.Direct冲突怎么办

问题描述:

C# Response.Write和 Response.Direct冲突怎么办
public partial class _Default : System.Web.UI.Page
{
String str = null;

protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{

Response.Write("alert('已放入购物车')");

}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("Next.aspx?ss=" + str);
}
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
StringBuilder strbuilder = new StringBuilder(str);
strbuilder.Append(item.Value + ", ");
str = strbuilder.ToString();
}
}
str = str.Substring(0, str.Length - 2);

}
}
点按钮1没弹出对话框,先点按钮1,在点按钮2传不了str值,要重新再checkBoxlist填一个或少一个选择再点按钮2才可以传值.这个怎么解决啊?

你是想实现弹出对话框,然后再跳转页面吧,你这样做显然是不行了,js可以实现.
把你的 Response.Redirect("Next.aspx?ss=" + str);改成
Response.Write("alert('注册成功!');location.href=('这里填写跳转页面');");我这里2个button各自要分别实现弹出对话框,和跳转页面。我想问有什么办法能避免冲突?那可能是你的button冲突了