Post Back does not work after writing files to response in ASP.NET

前端 未结 6 899
刺人心
刺人心 2020-12-15 15:00

What I have?

I have an ASP.NET page which allows the user to download file a on a button click. User can select the file he wants from

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-15 15:39

    I had same problem. Function to perform simple Response.Writer("") on Button Click event on aspx page was never firing.

    Method in class:

    public test_class()
    {
        public test_class() { }
    
        public static void test_response_write(string test_string) 
        {
            HttpContext context = HttpContext.Current;
            context.Response.Clear();
            context.Response.Write(test_string);
            context.Response.End();                   
        }
    }
    

    ASPX Page:

    protected void btn_test_Click(object sender, EventArgs e)
    {
        test_class.test_response_write("testing....");
    }
    

    While I was trying to find the reason, I just called same function on Page_Load event it worked.

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            test_class.test_response_write("testing....");
        }
    }
    

    Investigating the issue I found out that Master Page of that aspx page's body was under .

    I removed it, and it worked on Button_Click Event. I would recommend you to check that too.

提交回复
热议问题