无法使用codeehind将脚本插入到asp页面中

not able to insert script into asp page using codebehind

本文关键字:asp 插入 脚本 codeehind      更新时间:2023-09-26

我的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

请尝试以下操作:

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

希望它可以工作

试试这个。。。

代码

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

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

脚本

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

popupdiv是div的Id,您可以根据自己的需求设计