使用 jQuery (jGrowl) 的 .NET C# Web 应用程序的错误消息/通知组件

发布于 2024-08-08 10:54:39 字数 633 浏览 2 评论 0原文

我正在尝试为我们的 .net C# Web 应用程序创建错误消息/通知组件。要求是可以发布多条消息,它们通过部分回发持续存在,并且具有不同的类型(粘性、错误、通知)。

我有一个服务器端方法来捕获这些消息,并且我使用流行的 jQuery 插件 jGrowl 来显示这些消息。参见下文:

public void ShowErrorMessage(string Message)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorMessage", "<script type=\"text/javascript\">$.jGrowl('" + Message + "', { sticky: true });</script>");
}

目前,我正在使用 RegisterStartupScript 方法在 ShowErrorMessage 方法内触发 jGrowl 脚本,该方法对于第一条消息效果很好,但当然 RegisterStartupScript 不允许我随心所欲地触发 Javascript。每次点击 ShowErrorMessage 时如何触发 jGrowl 实例?

我的 JavaScript 知识有限。我愿意接受任何建议或替代方法。谢谢。

I’m trying to create an error message / notification component for our .net C# web application. The requirements are that multiple messages can be posted, that they persist through partial post backs, and have different types (sticky, error, notification).

I have a server-side method that captures these messages, and I am using the popular jQuery plug-in jGrowl to display these messages. See below:

public void ShowErrorMessage(string Message)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorMessage", "<script type=\"text/javascript\">$.jGrowl('" + Message + "', { sticky: true });</script>");
}

Currently I am firing the jGrowl script inside the ShowErrorMessage method using RegisterStartupScript approach which works fine for the first message but of course the RegisterStartupScript does not allow me to to fire Javascript on a whim. How can I fire an instance of jGrowl each time ShowErrorMessage is hit?

My JavaScript knowledge is limited. I am open to any suggestions or alternative methods. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

留一抹残留的笑 2024-08-15 10:54:39

你能提供更多信息吗?您提到进行部分回发。您正在执行完整回发还是部分回发?如果是部分的,怎么办...通过更新面板?

需要注意的一件事是,如果始终从同一位置调用该脚本,则 RegisterStartupScript 将仅注册该脚本的 1 个实例。它使用 this.GetType() 和“ErrorMessage”来检查它是否已经注册。如果您使用不同的消息调用它,该脚本将不会注册,因为它仍然是相同的类型和“ErrorMessage”。

Could you give a little more info. You mentioned doing partial postbacks. Are you doing a full postback or a partial? If partial, how so...through an updatepanel?

One thing to note is that the RegisterStartupScript will only register 1 instance of that script if it's always called from the same place. It's using this.GetType() and "ErrorMessage" to check to see if it's already been registered. If you call it with a different message, that script won't register since it's still the same type and "ErrorMessage".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文