2009-07-17 27 views
2

アップデートパネルをリフレッシュすることは可能ですか?レスポンスのリダイレクト直後(ダウンロードなど)は直ちに可能ですか? アップデートパネルの更新後にリダイレクト

私はこの試みた: - asyncpostbacktrigger

  • ダウンロード ボタンとして> -

    • 目に見えないボタンを、それが見えない ボタンをクリックonclientclick をクリックする>

    • の非表示ボタンのクリックイベントにより、更新がリフレッシュされます ペインリットル
    • が、その後、ダウンロードボタンをクリック イベントは目に見えないボタンはダウンロードボタンのクライアントスクリプトによってクリックされたいくつかの理由がダウンロード(ダウンロードを起動し、通常の ポストバック)

    を起動し、それはしていません更新パネルをリフレッシュしてください。

    なぜ動作しないのでしょうか? 他にもクリーンなテクニックがありますか?ここで

    は要素が宣言されている方法は次のとおりです。

     <asp:Button runat="server" ID="ButtonInvisible" Text="" Click="RefreshDisplay" /> 
    
    <asp:Button runat="server" ID="ButtonDownload" Text="Download" OnClientClick="clickInvisible(this.id)" Click="Download" /><Triggers> 
           <asp:AsyncPostBackTrigger ControlID="ButtonInvisible" /></Triggers> 
    

    //the javascript 
    <script type="text/javascript" language="javascript"> 
    function clickInvisible(idButton) { 
        document.getElementById('ButtonInvisible').click(); 
    
    }</script> 
    

    //the methods 
    Download(object source, EventArgs e){Response.Redirect("test.txt")} 
    RefreshDisplay(object source, EventArgs e){ ButtonCancel.Enabled = false;} 
    
  • 答えて

    0

    RefleshDisplayはButtonCancelバットを無効にするつもりですに?そして、あなたはすべてのトリガを使用せずに、プレーンJavaScriptでそれを行うことができます。

    <asp:Button runat="server" ID="ButtonDownload" Text="Download" OnClientClick="disableCancelButton()" Click="Download" /> 
    
    <script type="text/javascript" language="javascript"> 
    function disableCancelButton() { 
        document.getElementById('<%= ButtonCancel.ClientID %>').disabled = true; 
    } 
    </script> 
    
    +0

    コントロールのビューステートは正しい値に設定されません。したがって、次のポストバック状態では、このボタンの状態が失われます。 – teebot

    0

    私は同様の問題があったとhidden IFRAME trickを使用して、それを解決しました。不可視ボタンは必要ありません。実際、私のバージョンはJavaScriptを必要としません。

    protected void Button1_Click(object sender, EventArgs e) 
    { 
        // update some controls in the UpdatePanel 
        ... 
    
        // add an iframe which will start the download at the bottom of the UpdatePanel 
        var iframe = new HtmlGenericControl("iframe"); 
        iframe.Style["display"] = "none"; 
        iframe.Attributes["src"] = "http://...download url..."; 
        iframe.EnableViewState = false  // we only need the iframe for this one postback 
        myUpdatePanel.ContentTemplateContainer.Controls.Add(iframe) 
    } 
    
    関連する問題