0

私は2ページあります。main.aspx と download.aspx download.aspx の page_load は、ファイル テキスト ボックスをダウンロードし、main.aspx にダウンロード ボタンを配置します - page_load に機能はありません -download.aspx へのボタン リダイレクト - テキスト ボックスを空白のままにすることはできません。

テキストボックスに入力してボタンを押すと、ページはmain.aspxのままになり、ファイルはdownload.aspxからダウンロードされます。問題は、ダウンロードボタンを押した後にテキストボックスをクリアするにはどうすればよいですか?

私は試した:

  1. this.Textbox1.Text = "";リダイレクト前後。
  2. ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "document.getElementById('Textbox1').value =''", true);リダイレクト前後
  3. Response.Redirect("main.aspx);Response.Redirect("download.aspx");
  4. onclientclick = "validation()"

function validation() { document.getElementById('TextBox1').value= ""; }

私は検証を持っていることを覚えているので、4.動作しません。

5. 

    OnClientClick ="document.forms[0].target = '_blank';"/>

          Response.Redirect(”download.aspx”,false);
        Textbox1.Text="";

6. Textbox1.EnableViewState = false;

7.ボタンがクリックされ、main2.aspx にリダイレクトされ、main2.aspx でのページロードが download.aspx にリダイレクトされます。しかし、main.aspx のボタンをクリックした後、ファイルはダウンロードされますが、ページはまだ main.aspx に残っています。

上記の方法はどれも機能しません。他に何を試すことができますか? 問題は何ですか?テキストボックスを空白に設定できないのはなぜですか?

main.aspx

protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
   this.TextBox1.Text = "";
   Response.Redirect("download.aspx");
   this.TextBox1.Text = "";
}

ダウンロード.aspx

protected void Page_Load(object sender, EventArgs e)
{
   string reportPath = "C:\\form.pdf";

   Response.ContentType = "appplication/pdf";
   Response.AppendHeader("Content-Disposition", "attachment; filename=form.pdf");
   Response.TransmitFile(reportPath);
   Response.End();
}
4

2 に答える 2

0

テキストボックスの値をクリアするためにJavaScriptを試してください

于 2013-05-15T09:10:57.880 に答える
0

get メソッドを使用してダウンロードできると思います。ボタンの onClientClick コード:

function doGet(){
var txt=document.getElementById('<%=this.TextBox1.ClientID %>').value;
window.open ('download.aspx?file='+txt);
document.getElementById('<%=this.TextBox1.ClientID %>').value='';
}

そしてdownload.aspx.csで

次のように、main.aspx から値を取得できます。

string file=this.Request.QueryString["file"];

ReDirect メソッドを使用してダウンロード ページを要求しないでください。

于 2013-05-15T09:23:22.857 に答える