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(); }
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).
Microsoft SharePointC#.NET Programming
Last Comment
Randy Downs
8/22/2022 - Mon
Howard Bash
ASKER
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 Downs
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 Bash
ASKER
"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.