c# - 使用 UPDATE PANEL 时,应用程序不显示 javascript 消息

标签 c# javascript asp.net .net asp.net-ajax

我正在制作 ASP.NET 应用程序 (C#)。 [ Visual Studio 2010]

因为当我尝试使用 javascript 使用客户端消息时,它会在未使用更新面板时显示消息。

但是,一旦我将更新面板添加到我的应用程序以防止它回发,它就不会在插入记录时向我显示此类 javascript 消息。

我尝试通过以下方式显示消息:

Response.Write("<head><script type='text/javascript'>alert('Member Registered Sucessfully')</script></head>");

我的代码:

 try
{
    con.Open();
    cmd = new SqlCommand("insert into register values(@name,@city,@address,@mobile)",con);
    cmd.Parameters.AddWithValue("@name",txtName.Text);
    cmd.Parameters.AddWithValue("@city", ddlCity.Text);
    cmd.Parameters.AddWithValue("@address",txtAddress.Text);
    cmd.Parameters.AddWithValue("@mobile", txtMobile.Text);
    da = new SqlDataAdapter(cmd);
    ds = new DataSet();
    da.Fill(ds);
    int res=cmd.ExecuteNonQuery();
    if (res > 0)
    {
        Response.Write("<head><script type='text/javascript'>alert('Member Registered Sucessfully')</script></head>");
    }
    else
    {
        Response.Write("<head><script type='text/javascript'>alert('Member Not Registered Sucessfully')</script></head>");
    }
    con.Close();

}

请告诉我我在哪里做 mastake。

请指导我。

最佳答案

如果你有更新面板使用ScriptManager.RegisterClientScriptBlock如下

ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Member Registered Sucessfully');", true)

您不能在异步回发期间使用 Response.Write

关于c# - 使用 UPDATE PANEL 时,应用程序不显示 javascript 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16603145/

相关文章:

c# - 是否可以将 DataRow 插入到索引 0 处的 DataTable 中?

python - Python中C#的WriteAllBytes等效函数

javascript - 我的 ajax 方法中的属性列表后缺少 }///

javascript - 使用 IIFY(Immediately-Invoked Function Expression) 和 {...} 之间有什么区别吗

c# - 如何在 MVC 的 Controller 中获取 DropDownList SelectedValue

javascript - 文件下载弹出窗口不起作用

c# - 在 C# 应用程序中获取插件或扩展功能的步骤是什么?

javascript - 我应该在 service worker 中使用 self 还是 this ?

javascript - 是否可以使用前端 JavaScript 编写 JSON 文件?

c# - C#中的@语法是什么