0

我有一个通知 j-query 插件.. 我在我的页面中品尝它(工作 100%)但是当我想在事件 SqlDataSource1_Deleted 和 response.write 方法中使用它时它不起作用

Protected Sub SqlDataSource1_Deleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Deleted

    Response.Write("<script  type='text/javascript'> showNotification({message: 'This is a sample Success notification', type: 'success' }); </script>")
End Sub
4

1 回答 1

2

如果您Response.Write在页面中使用,您将把代码放在 HTML 文档本身之前。这意味着它将在 jQuery 或任何插件加载之前运行。(而且它可能会导致页面以怪异模式呈现,这可能会破坏整个布局。)

使用RegisterStartupScript方法在页面中添加脚本:

Protected Sub SqlDataSource1_Deleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Deleted
  Page.ClientScript.RegisterStartupScript(Page.GetType(), "notification", "showNotification({message: 'This is a sample Success notification', type: 'success' });", true)
End Sub
于 2012-05-23T14:52:56.273 回答