ボタンが更新パネルの外にあるという問題がある場合は、次の手順を実行できます。ページ コードバインド:
protected void Page_Load(object sender, EventArgs e)
{
string hideScript = string.Format("function updateButtonVisibility( visibility ) {{ var button = $('#{0}'); if (visibility) {{ button.show(); }} else {{ button.hide(); }} }}", this.button1.ClientID);
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "updateButtonVisibility", hideScript, true);
}
そして、ユーザー コントロール コマンド ハンドラーで次のようにします。
bool shouldButtonBeVisible = false; //update this appropriately in your logic
ScriptManager.RegisterStartupScript(this, this.GetType(), "upUpdateButtonVisibility", "updateButtonVisibility(" + shouldButtonBeVisible ? "true" : "false" + ");", true);
これにより、UC とページの間に密接な依存関係が生じることに注意してください。このコントロールを使用するすべてのページで、このスクリプトが登録されている必要があります。これを回避する方法はいくつかありますが (関数スクリプト コールバックを呼び出すように設定する、その JavaScript 関数が存在するかどうかを検出するなど)、少なくともこれで動くはずです。
更新パネルが終了した後、キーオフできる特定の何かがページにある場合は、終了要求ハンドラーを登録することをお勧めします。
$(function() { Sys.WebForms.PageRequestManager.getInstance().add_endRequest(updatePanelEndRequestHandler); } );
function updatePanelEndRequestHandler() {
var shouldBeVisible = $('.MyClassThatSaysIShouldntAllowMoreButtons').length > 0; //do some checking on the grid
updateButtonVisibility(shouldBeVisible);
}