13

ボタンを使用してフォームを送信した後、toastr メッセージ (情報、エラーなど) を表示し、asp.net webform の gridview コントロール (更新パネルにあります) を更新しようとしています。ありがとう

4

2 に答える 2

13

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

于 2013-03-21T13:31:49.577 に答える