1

I have a DDL and Button which when clicked create a dynamic table; all controls are within an UpdatePanel.

Outside the panel I have 2 buttons which should be hidden until the table is created. If the buttons start as visible = false and then I set them to true after I click the GO button from the UpdatePanel, they never become visible

If I add a second UpdatePanel and put the 2 buttons in there it sort of works but I always get this error when clicking on either button:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: 
The message received from the server could not be parsed.

How to fix that?

4

2 に答える 2

3

更新パネル内の 2 つのボタンを移動します。更新パネルのコントロールのみが Ajax 呼び出しで更新されます。つまり、Ajax 呼び出しでコード ビハインドを使用してコントロールの状態を変更する場合は、それを [更新] パネル内に含める必要があります。Ajax 呼び出しでは、更新パネルの外でコントロールを変更することはできません。

更新 これにはイベントハンドラーが必要です。ボタンを可視にする= true; visibility:hidden を設定し、呼び出しが完了したら以下のように変更します。

<script type="text/javascript" language="javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandle);
      Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandle);
      function beginRequestHandle(sender, Args) {
      //Do something when call begins.
        }

function endRequestHandle(sender, Args) {
document.getElementById("Button1").style.visibility = "visible";
document.getElementById("Button2").style.visibility = "visible";
}
      </script>
于 2012-07-03T10:44:51.073 に答える
0

はい、Ashwinが言ったように、更新パネルの外側にボタンが必要な場合は、JSからボタンを表示する必要があります。ページにscriptmanagerがある場合は、JS関数を呼び出して、このようにコードビハインドからボタンを表示できます。

<script type="text/javascript" language="javascript">
   function showButtons(){
     document.getElementById("<%= Button1.ClientID %>").style.visibility = "visible";
     document.getElementById("<%= Button2.ClientID %>").style.visibility = "visible";
   }
</script>

ボタンがサーバーコントロールの場合は、コードブロック<%=%>を使用してボタンのクライアントIDを取得します。動的テーブルを作成した後のコードビハインドでこれを使用します

 ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showButtons", "showButtons();", true);
于 2012-07-03T11:56:12.240 に答える