1

ビジュアル Web パーツで SharePoint DateTimeControl を使用しています。ここでは、選択した日付が将来の日付であってはならないことを確認しています。このため、ユーザーが将来の日付を入力した場合、その警告メッセージを表示するために ScriptManager.RegisterStartupScript を使用しています。これらのアクティビティは、OnDateChanged イベントで処理されます。アラート メッセージを表示し、ClearSelection() メソッドを使用して DateTimecontrol から選択した日付をクリアすると、値がクリアされません。以下に私のコードを貼り付けました。

設計側:

<SharePoint:DateTimeControl ID="dtManagerJoiningDate" runat="server" AutoPostBack="true"
                    DateOnly="true" OnDateChanged="dtManagerJoiningDate_OnDateChanged" />

コードビハインド:

 protected void dtManagerJoiningDate_OnDateChanged(object sender, EventArgs e)
    {
        if (dtManagerJoiningDate.IsValid)
        {
            if (dtManagerJoiningDate.SelectedDate > todayDate)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Invalid Date", "alert('Joining Date should be past Date');", true);
                dtManagerJoiningDate.ClearSelection();
            }
        }
    }

これについて私を助けてください.....

4

1 に答える 1

1

更新パネルとスクリプト マネージャーを使用して問題を再現できました。

理由はわかりませんが、clearSelection コードをOnPreRenderに入れることで、これが機能するようになりました。

bool _clearSelection = false
protected void dtManagerJoiningDate_OnDateChanged(object sender, EventArgs e)
{
    if (dtManagerJoiningDate.IsValid)
    {
        if (dtManagerJoiningDate.SelectedDate > todayDate)
        {
           _clearSelection = true;
        }
    }
 }

    protected override void OnPreRender(EventArgs e)
    {
        //see if it clear selection is set
        if(_clearSelection)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Invalid Date",           "alert('Joining Date should be past Date');", true);
            dtManagerJoiningDate.ClearSelection();
         }
    }
于 2013-04-04T14:42:24.623 に答える