0

updatepanel 内にいくつかのテキストボックスがあり、簡単な検証を行っています。検証チェックが失敗すると、エラー メッセージがダイアログ ボックスに表示されます。私の問題は、RegisterClientScriptBlock が、テキスト ボックスの 1 つの検証が失敗したときにダイアログ ボックスを表示するが、他のテキスト ボックスは失敗しないことです。どちらの場合も、イベントが発生しています。以下のコードでは、txtCustMSCName (外側の If ステートメントの Else の下にある 2 番目のテキスト ボックス) テキスト ボックスが検証基準に失敗すると、ダイアログ ボックスは正しく表示されますが、txtMSCName テキスト ボックスが失敗すると表示されません。なぜこれが起こっているのでしょうか?txtMSCName が ReadOnly=True に設定されていることと関係がありますか?

VB:

If chkCustomMSC.Checked = False Then

    If txtMSCName.Text = "No sales contact for this account" Then

        DialogMsg = "alert('There are no main sales contacts for this account in CRM; please check the 'Custom MSC' box and " _
                        + "manually enter the main sales contact information');"
        ErrorDialog(DialogMsg)

        Exit Sub

    End If

Else

    If txtCustMSCName.Text = "" Then

        DialogMsg = "alert('You must enter a main sales contact name');"
        ErrorDialog(DialogMsg)

        Exit Sub

    End If

End If

Protected Sub ErrorDialog(ByVal Message As String)

    ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), Message, True)

End Sub

マークアップ:

<asp:TextBox ID="txtMSCName" runat="server" ReadOnly="true" CssClass="DisplayTextBoxStyle"/>
<asp:TextBox ID="txtCustMSCName" runat="server" CssClass="MSCInputTextBoxStyle"/>    
4

2 に答える 2

1

問題は、あなたが持っているDialogMsg 文字列'Custom MSC'にあります。single quote character結果の JavaScript が整形式で、Web ブラウザで正しく処理できるように、すべてを適切にエスケープする必要があります。

JavaScript 関数は単一引用符で開始するためalert()、別の単一引用符で終了する必要があります。

例 1: alert('hello world');うまくいきます。

例 2: alert('hello 'world'');動作しません。実際には JavaScript エラーが発生します。

SCRIPT1006: ')' が必要です

これを修正するには、アラート文字列内のすべての単一引用符をエスケープする必要があります。

例 2 は次のようになります。 alert('hello \'world\'');

したがって、質問を支援するには、これから変更する必要があります。

DialogMsg = "alert('There are no main sales contacts for this account in CRM; please check the 'Custom MSC' box and " _
+ "manually enter the main sales contact information');"

これに:

DialogMsg = "alert('There are no main sales contacts for this account in CRM; please check the \'Custom MSC\' box and " _
+ "manually enter the main sales contact information');"

\'カスタム MSCに注意してください\'

于 2014-06-26T20:11:08.267 に答える
0

Page.ClientScript.RegisterClientScriptBlock() を試してください。Page.RegisterClientScriptBlock が asp.net のバージョンで廃止されたと思われるため

于 2014-06-26T20:02:29.617 に答える