显示消息用户从ASP.NET使用jQuery [英] Displaying messages to user from ASP.NET using jQuery
问题描述
在ASP.NET中开发各种网络应用程序,我发现自己需要的各种动作已经完成后,将消息发送给用户。有关示例,如果文件已经成功上传或数据库记录已更新。此外,如果有错误欲通知用户。
In developing various web application in ASP.NET I find myself needing to send messages back to the user after various actions have been performed. For examples if files have been uploaded successfully or a database record has been updated. Also, if there are errors I want to notify the user.
到目前为止,我一直在创造服务器端变量包含我要显示给用户的消息,然后使用最初隐藏,但然后回发上可见显示的邮件ASP.NET Label控件。这个效果很好,但我真的很喜欢这个选项来显示一个模式jQuery的窗口的一些消息,这样我可以保证他们看到的消息。
So far I have been creating server side variables that contains the messages I want to display to the users and then using ASP.NET Label controls that are initially hidden but then made visible on postback to display the messages. This works well, but I would really like the option to display some messages in a modal jQuery windows so that I can assure they see the message.
任何人都可以提出一些框架或者技术,他们已经找到有用的来完成这个任务?谢谢你。
Can anyone suggest some frameworks or perhaps techniques they have found useful to accomplish this task? Thanks.
推荐答案
我使用 showmessage 的jQuery插件与页面上的一些扩展方法像这种组合:
I use the showmessage jquery plugin combined with some extension methods on the Page like this:
/// <summary>
/// Shows the errors.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="text">The text.</param>
public static void ShowError(this Page page, string text)
{
ShowNotification(page, NotificationType.Error, text, false);
}
/// <summary>
/// Shows the information.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="text">The text.</param>
public static void ShowInformation(this Page page, string text)
{
ShowNotification(page, NotificationType.Information, text, true);
}
/// <summary>
/// Shows the errors.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="text">The text.</param>
public static void ShowNotification(this Page page, NotificationType notificationType, string text, bool autoClose)
{
string className = null;
switch (notificationType)
{
case NotificationType.Error:
className = "fail";
break;
case NotificationType.Information:
className = "notification";
break;
case NotificationType.Success:
className = "success";
break;
}
string notification = "jQuery('body').showMessage({'thisMessage':['" + text.Replace(Environment.NewLine, "','") + "'],'className':'" + className + "','autoClose':" + autoClose.ToString().ToLower() + ",'delayTime':4000,'displayNavigation':" + (!autoClose).ToString().ToLower() + ",'useEsc':" + (!autoClose).ToString().ToLower() + "});";
if (RadAjaxManager.GetCurrent(page) != null)
{
RadAjaxManager.GetCurrent(page).ResponseScripts.Add(notification);
}
else
{
if (ScriptManager.GetCurrent(page) != null)
{
ScriptManager.RegisterStartupScript(page, page.GetType(),
"notification",
notification,
true);
}
else
{
page.ClientScript.RegisterStartupScript(page.GetType(),
"notification",
notification,
true);
}
}
}
/// <summary>
/// Shows the notifications.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="text">The text.</param>
public static void ShowSuccess(this Page page, string text)
{
ShowNotification(page, NotificationType.Success, text, true);
}
}
它并不完美,但我想要做什么,这很简单,一切都在一个地方。
It's not perfect but it does what I want, it's simple and everything is in one place.
这篇关于显示消息用户从ASP.NET使用jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!