无法使用后面的代码将脚本插入到asp页面中

时间:2013-02-15 07:37:09

标签: javascript asp.net code-behind

我的asp.net/c#页面中有一个简单的gridview控件我希望在删除我的行时显示“删除成功”的消息我尝试使用它但它没有效果。 我的代码就是这个..

script = string.Format(@"<script type='text/javascript'>alert('Successfully deleted');</script>");
if (Page != null && !Page.ClientScript.IsClientScriptBlockRegistered("alert"))
{
     Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "alert", script);
}

任何人都可以帮助我,我是新手。

Thaks
-Vishu

2 个答案:

答案 0 :(得分:0)

请试试这个:

ScriptManager.RegisterStartupScript(this.Page , typeof(Page) , Guid.NewGuid().ToString() , "alert('Successfully deleted');" , true);

希望它可能有用

答案 1 :(得分:0)

试试这个......

<强> CODE

Page.ClientScript.RegisterStartupScript(this.GetType(), "Call my function", "popup();", true);

其中 popup()是一个javascript函数。

<强> SCRIPT

function popup() {
    $("#popupdiv").fadeIn('slow');
 }

popupdiv 是您可以根据自己的要求设计的div的ID