Ajax中使用Response.Write输出javascript脚本出错的解决办法

来源:互联网 发布:红色套装裙妈妈淘宝网 编辑:程序博客网 时间:2024/05/12 15:57

protected void Button1_Click(object sender, EventArgs e)
    {
       1. Response.Write("<script language=javascript>/r alert(/"修改失败!/");/r</script>");

       2. ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "alert", "alert('你好 !');", true);     
     3. Page.RegisterStartupScript("alert", "<script language='javascript'>window.showModelessDialog(/"javascript:alert('你好 !');/",/"/",/"status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;/")</script>");
       4. //ClientScript.RegisterClientScriptBlock(typeof(UpdatePanel), "alert", "<script>alert('自己看着办!')</script>", true);
    }

前台页面代码;


<form id="form1" runat="server">
    <div>
     <div>
        <asp:ScriptManager id="ScriptManager1" runat="server">
        </asp:ScriptManager>
   
    </div>
        <asp:UpdatePanel id="UpdatePanel1" runat="server">
        <Triggers>
        <asp:PostBackTrigger ControlID="Button1" />
        </Triggers>
            <contenttemplate>
<asp:Button id="Button1" runat="server" Text="Button" OnClick="Button1_Click"></asp:Button>
</contenttemplate>
        </asp:UpdatePanel>

    </div>
    </form>

其中第一种要加上<Triggers>
        <asp:PostBackTrigger ControlID="Button1" />
        </Triggers>

下面几种不用加。

但是我观察了下,第一种,好像刷新,第二第三种不刷。第四种好像不可以,没有反应...不过网上说可以,不知了...

ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "aaa", "alert('删除成功')", true);

        Response.Redirect("~/JH_Search_GreenTotal.aspx?UnitID=" + nnUnitID.ToString() + "&nMonth=" + nnMonth.ToString());