我有一个通知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
答案 0 :(得分:2)
如果在页面中使用Response.Write
,则会将代码放在HTML文档本身之前。这意味着它将在jQuery或任何插件加载之前运行。 (而且它可能导致页面以怪癖模式呈现,这可能会破坏整个布局。)
使用RegisterStartupScript
method在页面中添加脚本:
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