3
votes

Hello Everybody I am using c#.net to make webapplication. I am making a webpage that export gridview data to excel. My code is as follow

    protected void btnexport_Click(object sender, EventArgs e)
    {
        btnsubmit.Visible = false;
        exporttoexcel();
        expToExcel();
    }

    public override void VerifyRenderingInServerForm(Control control)
    {
        //base.VerifyRenderingInServerForm(control);
    }

    public void exporttoexcel()
    {
        Context.Response.Clear();

        Context.Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");

        Context.Response.Charset = "";

        Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

        Context.Response.ContentType = "application/vnd.xls";

        System.IO.StringWriter stringWrite = new System.IO.StringWriter();

        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

        GridView1.RenderControl(htmlWrite);

        Context.Response.Write(stringWrite.ToString());

        Context.Response.End();

    }

My gridview data is export to excel successfully but on EXPORTTOEXCEL button click event i am trying to false the visible property of another button submit, but i am successful to do it so please tell me how i set the visible property to false on EXPORTTOEXCEL button click event

Please give me reply soon my work is in midway

thank u to all in advance

1
I guess btnexport.Visible = false; - Loki Kriasus

1 Answers

1
votes

You are setting the button visibility to false on postback, but in the same request you clear the response and output your Excel data. So the control tree with the invisible button never makes it back to the client.

I am guessing you want to do this in order to hide the button from the user while you are generating the Excel. If this is the case, your best bet is to use client-side javascript to hide the button.

You could insert this javascript in the button's OnClientClick property:

document.getElementById('<%=btnexport.ClientID%>').style.display = none;