SharePoint 2010 Web Part Gridview to CSV

I have written an web part that has a gridview on it that I populate and display on assorted web part pages.   All that seems to work fine.  Now I need to capture the gridview data and present it to a user on their clicking a "Load CSV" button on that web part.  

The code follows and indeed works:
   private void ExportGridToCSV()
        {            
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=Employee.csv");
            Response.Charset = "";
            Response.ContentType = "application/text";
            GridEmployee.AllowPaging = false;
            GridEmployee.DataBind();

            StringBuilder columnbind = new StringBuilder();
            for (int k = 0; k < GridEmployee.Columns.Count; k++)
            {

                columnbind.Append(GridEmployee.Columns[k].HeaderText + ',');
            }

            columnbind.Append("\r\n");
            for (int i = 0; i < GridEmployee.Rows.Count; i++)
            {
                for (int k = 0; k < GridEmployee.Columns.Count; k++)
                {

                    columnbind.Append(GridEmployee.Rows[i].Cells[k].Text + ',');
                }

                columnbind.Append("\r\n");
            }
            Response.Output.Write(columnbind.ToString());
            Response.Flush();
            Response.End();

        }

Open in new window


The problem is that once the click event calls this code, the page no longer seems to be connected to the code behind and subsequent clicks don't get handled (I have a breakpoint which is never reached in the beginning of the click events).
LVL 1
Howard BashSenior Software EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Howard BashSenior Software EngineerAuthor Commented:
Why would that be?  The function gets called when I click a button which is part of the web part, but the button subsequently doesn't fire the event nor does another button on that same web part.
Randy DownsOWNERCommented:
That example was not the best since it was only losing its previous text not the code.

As I understand it your code works on 1st click but not after that, Anything detected in Console? Perhaps your code is looking for a status from onClick or something along those lines. Is the button even enabled after the click?

It might be helpful to post your button script.
Howard BashSenior Software EngineerAuthor Commented:
"That example was not the best since it was only losing its previous text not the code. "  - I have no clue what you're referring to in that statement.

The button does click but the event handler code's breakpoint isn't hit.

There is no button script.  This is CodeBehind C#.
Randy DownsOWNERCommented:
It would be helpful to see the asp code (e.g., asp:Button) . Can you move your break point to somewhere that is triggered?
Randy DownsOWNERCommented:
I don't see anything in your code about a button click. Maybe you can adapt this .

... click the Design button in the bottom of VS. Now you will see a visual representation of our page. We wish to add a Click event to the button, and this is very simply - just doubleclick the GreetButton, and you will be taken to the CodeBehind file of our page. As you can see, a fine new method has been added, called GreetButton_Click. If you have a look at the Default.aspx file (you need to go from Design view to Source view), you will see that an attribute has been added to our Button control, telling which method to call when the button is clicked. All this work done with a simple doubleclick.

Now lets add some code to our new event. We wish to use the text from the TextBox, on our good old Label with the "Hello, world!" text. This is also very simple, and all it requires is a single line of code:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SharePoint

From novice to tech pro — start learning today.