0

i have a notification j-query plugin .. i taste it in my page (working 100%) but when i want to use it in a event SqlDataSource1_Deleted with the response.write method it does not work

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
Yassine edouiri
  • 281
  • 3
  • 14
  • 30

1 Answers1

2

If you use Response.Write in a page, you will be putting the code before the HTML document itself. This means that it will run before jQuery or any plugin is loaded. (And also that it may cause the page to be rendered in quirks mode, which would probably break the entire layout.)

Use the RegisterStartupScript method to add a script in the page:

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
Guffa
  • 687,336
  • 108
  • 737
  • 1,005