0

html入力でNOTIFYを使用して、レコードが保存されたかどうかをユーザーに通知しています。そしてそれはうまく動作します。しかし、コード ビハインド ファイルから使用しようとすると、そうではありません。JavaScript はクライアント側のテクノロジであることを理解しており、RegisterStartupScript を使用してみましたが、うまくいきませんでした。

このようなボタンクリックで使用しようとしています

        protected void Button1_Click1(object sender, EventArgs e)
    {
        var script = " $.notify.success('I do not want to close by myself close me ', { close: true });";
        ClientScript.RegisterStartupScript(typeof(Page), "ButtonAlert", script, true);

    }

しかし運がない。

データベースが更新されたら、一番上に通知バーを表示する方法が必要だと確信しています。関数を使用してそれを行うことができるとしましょう。
私のスクリプトは次のように定義されています

 <!-- Notify Implementation -->
<script src="../Scripts/jquery-1.9.0.js" type="text/javascript"></script>
<link href="../Styles/notify.css" rel="stylesheet" type="text/css" />
<script src="../Scripts/notify.js" type="text/javascript" ></script>

<script type="text/javascript">

     function myNotify() {
         $.notify.success('I do not want to close by myself close me ', { close: true });
     };

誰か助けてくれませんか

4

3 に答える 3

1

このようにしてみてください:-

  System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append("<script language='javascript'>");
                sb.Append("function notify(){");
                sb.Append("$.notify.success('I do not want to close by myself close me ', { close: true });");
    sb.Append("}");
                sb.Append("/script>");

 ClientScript.RegisterStartupScript(typeof(Page), "ButtonAlert", sb, true);
于 2013-01-28T06:28:53.097 に答える
0

これを試して :

Page.ClientScript.RegisterStartupScript(this.GetType(),"ButtonAlert","myNotify()",true);
于 2013-01-28T06:26:15.060 に答える
0

HEREで説明されているように、これで問題が解決しました。私はヘルパークラスを使用しましたが、問題は解決しました。

    using System.Web.UI;

public static class NotificationHelper
{
    /// <summary>
    /// Shows the successful notification.
    /// </summary>
    /// <param name="page">The page.</param>
    /// <param name="message">The message.</param>
    public static void ShowSuccessfulNotification(this Page page, string message)
    {
        page.ClientScript.RegisterStartupScript(page.GetType(), "notificationScript",
                                                "<script type='text/javascript'>  $(document).ready(function () {  $.notify.success('I do not want to close by myself close me ', { close: true });});</script>");
    }
}
于 2013-01-28T09:36:49.567 に答える