如果我有`

时间:2011-02-02 03:18:56

标签: asp.net gridview objectdatasource

我刚注意到,如果我删除了<asp:UpdatePanel ...,那么我会收到提醒信息

如何从代码隐藏中提醒消息,我尝试了多种方式,但我从未收到过警报消息,下面是我的代码:

protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
  if (e.CommandName == CRUID.Delete.ToString())
  {

  ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", "alert('Deleted successfully!');", true);

or

// Define the name and type of the client scripts on the page.
         String csname1 = "PopupScript";
         Type cstype = this.GetType();

         // Get a ClientScriptManager reference from the Page class.
         ClientScriptManager cs = Page.ClientScript;

         // Check to see if the startup script is already registered.
         if (!cs.IsStartupScriptRegistered(cstype, csname1))
         {
             StringBuilder cstext1 = new StringBuilder();
             cstext1.Append("<script type=text/javascript> alert('Hello World!') </");
             cstext1.Append("script>");

             cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
         }
   }
}

protected override void Page_Load(object sender, EventArgs e)
{
   gv.DataSourceID = "gvDataSource";
}

ps:iam使用objectdatasource来绑定我的gridview控件

1 个答案:

答案 0 :(得分:0)

尝试改变:

ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Deleted successfully!');", true);