Answered by:
Toastr and Ajax Loading Panel

Question
-
User-1188570427 posted
Is it possible to use toastr messages AND Ajax Loading panels at the same time.
I have toastr installed and it will work as long as I am not using Ajax. If I use Ajax, I guess the ajax is killing it.
Any thoughts?
Friday, June 1, 2018 3:50 AM
Answers
-
User-1188570427 posted
I had to use ScriptManager. instead of page.ClientScript.RegisterStartupScript.
Public Shared Sub ShowToastr(ByVal page As Page, ByVal message As String, ByVal title As String, ByVal typeOption As ToastrTypeOption) Dim serializer As JsonSerializer = New JsonSerializer() Dim theToastrOptionInfo As ToastrOptionsDto = New ToastrOptionsDto() Dim json As String = JsonConvert.SerializeObject(theToastrOptionInfo) Dim scriptText As String = String.Format("toastr['{0}']('{1}', '{2}', {3});", GetDefaultValueFromEnumValue(typeOption).ToLower(), message, title, json) ScriptManager.RegisterStartupScript(page, page.GetType(), Guid.NewGuid().ToString(), scriptText, True) End Sub
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 18, 2018 2:29 PM
All replies
-
User-1768369891 posted
Is it possible to use toastr messages AND Ajax Loading panels at the same time.
I have toastr installed and it will work as long as I am not using Ajax. If I use Ajax, I guess the ajax is killing it.
Any thoughts?
Actually problem is that JavaScript not alive after perform ajax action.
Similar Answer
https://www.codeproject.com/Articles/1139528/Toastr-Net-Yet-Another-Notification-Plugin-Extende
Friday, June 1, 2018 4:08 AM -
User61956409 posted
Hi tvb2727,
If the question is that the jQuery event is lost (or not executed as expected) after you do the partial postback with UpdatePanel control, you could refer to the following code snippet to rebind your jQuery events.
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link href="http://codeseven.github.io/toastr/build/toastr.min.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="http://codeseven.github.io/toastr/build/toastr.min.js"></script> <script> $(function () { showtoastr(); }); function showtoastr() { $("#btnshow").click(function () { toastr.success("Your infos are updated with succes !"); }); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <script> Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function (evt, args) { showtoastr(); }); </script> <%=DateTime.Now %> <asp:Button ID="btnshow" runat="server" Text="Show" /> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html>
With Regards,
Fei Han
Friday, June 1, 2018 7:13 AM -
User-1188570427 posted
Okay, let me look at these.
I just would like to use Toastr after my ajax is done etc.
Saturday, June 2, 2018 9:51 PM -
User-1188570427 posted
I had to use ScriptManager. instead of page.ClientScript.RegisterStartupScript.
Public Shared Sub ShowToastr(ByVal page As Page, ByVal message As String, ByVal title As String, ByVal typeOption As ToastrTypeOption) Dim serializer As JsonSerializer = New JsonSerializer() Dim theToastrOptionInfo As ToastrOptionsDto = New ToastrOptionsDto() Dim json As String = JsonConvert.SerializeObject(theToastrOptionInfo) Dim scriptText As String = String.Format("toastr['{0}']('{1}', '{2}', {3});", GetDefaultValueFromEnumValue(typeOption).ToLower(), message, title, json) ScriptManager.RegisterStartupScript(page, page.GetType(), Guid.NewGuid().ToString(), scriptText, True) End Sub
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 18, 2018 2:29 PM