Я пытаюсь отобразить сообщение toastr (информация, ошибка и т. Д.) После отправки формы с помощью кнопки и обновления элемента управления gridview (который находится в панели обновления) в веб-форме asp.net. . БлагодаряДобавление toastr javascript asp.net webform
ответ
Вы можете сделать это с помощью метода Page.ClientScript.RegisterStartupScript
Пример:
Page.ClientScript.RegisterStartupScript(this.GetType(),
"toastr_message", "toastr.error('There was an error', 'Error')", true);
Но я бы, вероятно, создать метод метод или расширения для обработки, что для меня:
public static void ShowToastr(this Page page, string message, string title, string type = "info")
{
page.ClientScript.RegisterStartupScript(page.GetType(), "toastr_message",
String.Format("toastr.{0}('{1}', '{2}');", type.ToLower(), message, title), addScriptTags: true);
}
Применение:
ShowToastr(this.Page, "Hello world!", "Hello");
Если вы хотите что-то немного более надежные, вы могли бы сделать type
параметр enum
.
Я думаю, что это аккуратно и действительно крепко ... Спасибо – dblay
Вызов из веб-формы, (обратите внимание, это форма MasterDetail так есть MasterPage.
MasterPage.ShowToastr (Page, "Message Здесь", "Title Here", "Info", False, «toast- снизу вся ширина», False)
реализация VB.NET ShowToastr в мастер-странице (VB)
Public Shared Sub ShowToastr(ByVal page As Page, ByVal message As String, ByVal title As String, Optional ByVal type As String = "info", Optional ByVal clearToast As Boolean = False, Optional ByVal pos As String = "toast-top-left", Optional ByVal Sticky As Boolean = False)
Dim toastrScript As String = [String].Format("Notify('{0}','{1}','{2}', '{3}', '{4}', '{5}');", message, title, type, clearToast, pos, Sticky)
page.ClientScript.RegisterStartupScript(page.[GetType](), "toastr_message", toastrScript, addScriptTags:=True)
End Sub
функция ShowToastr Javascript находится в главной странице в качестве общей функции.
<link href="./Media/css/Grey/ListBox.Grey.css" rel="stylesheet" type="text/css" />
<link href="./Media/css/WebTrack.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.1/css/toastr.css"
rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.1/js/toastr.js"
type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function Notify(msg, title, type, clear, pos, sticky) {
// toastr.options.positionClass = "toast-bottom-right";
// toastr.options.positionClass = "toast-bottom-left";
// toastr.options.positionClass = "toast-top-right";
// toastr.options.positionClass = "toast-top-left";
// toastr.options.positionClass = "toast-bottom-full-width";
// toastr.options.positionClass = "toast-top-full-width";
// options = {
// tapToDismiss: true,
// toastClass: 'toast',
// containerId: 'toast-container',
// debug: false,
// fadeIn: 300,
// fadeOut: 1000,
// extendedTimeOut: 1000,
// iconClass: 'toast-info',
// positionClass: 'toast-top-right',
// timeOut: 5000, // Set timeOut to 0 to make it sticky
// titleClass: 'toast-title',
// messageClass: 'toast-message' }
if (clear == true) {
toastr.clear();
}
if (sticky == true) {
toastr.tapToDismiss = true;
toastr.timeOut = 10000;
}
toastr.options.onclick = function() {
//alert('You can perform some custom action after a toast goes away');
}
//"toast-top-left";
toastr.options.positionClass = pos;
if (type.toLowerCase() == 'info') {
toastr.options.timeOut = 1000;
toastr.tapToDismiss = true;
toastr.info(msg, title);
}
if (type.toLowerCase() == 'success') {
toastr.options.timeOut = 1500;
toastr.success(msg, title);
}
if (type.toLowerCase() == 'warning') {
toastr.options.timeOut = 3000;
toastr.warning(msg, title);
}
if (type.toLowerCase() == 'error') {
toastr.options.timeOut = 10000;
toastr.error(msg, title);
}
}
</script>
Я надеюсь, что это поможет кому-то, поскольку я пытался целую вечность, чтобы получить параметры toastr, интегрированные в один звонок. Если вы хотите иметь больше опций для вызова toastr, добавьте дополнительные параметры в функции. Все параметры, которые могут быть установлены, находятся в комментариях (javascript).
- 1. Toastr Alert Asp.Net Vb
- 2. ASP.NET MVC, гибрид Webform
- 3. jQueryMobile в ASP.NET WebForm
- 4. заменить в asp.net webform
- 5. asp.net Обработка формы Webform
- 6. ASP.NET Webform Routing
- 7. MasterPage Issue - ASP.NET Webform
- 8. MVC для ASP.net Webform
- 9. Asp.net webform устройство отзывчивое
- 10. ASP.Net MVC C# с Toastr не minifing javascript
- 11. захват данных из ASP.NET webForm
- 12. Добавление переменных в окно сообщения toastr js
- 13. Значение формы Webform в javascript
- 14. Podio Javascript WebForm
- 15. смешивание asp.net webform и asp.net mvc
- 16. Как скрыть полный asp.net webform
- 17. Colorbox + ASP.NET WebForm Кнопка отправки
- 18. NHibernate StructureMap ASP.NET webform System.OutOfMemoryException
- 19. routing webform в asp.net mvc
- 20. asp.net Браузер WebForm или MVC
- 21. конвертировать asp.net webform в mvc
- 22. Добавление динамического CalendarExtender в WebForm в CodeBehind
- 23. ASP.Net с javascript: использование нескольких экземпляров элемента управления в Webform
- 24. как передать serveride Введите в asp.net webform для использования javascript
- 25. jquery выбирает возвращаемое неопределенное значение - asp.net webform
- 26. ASP.NET webform Показать информацию из базы данных
- 27. Как использовать toastr?
- 28. Показаны только 1 toastr
- 29. jqGrid + ASP.NET WebForm (C#) Возможности поиска
- 30. Генератор Webform?
Только что получил; ScriptManager.RegisterStartupScript (это, GetType(), ", toastr", "toastr.info ('Клиент добавлен', 'Сообщение')", true); – dblay
Интересный подход с использованием ScriptManager ... аккуратный! –