简体   繁体   中英

GridView to Excel ASPX in SharePoint

I have an ASPX file which I am running in SharePoint that has a GridView which I am attempting to export into an excel spreadsheet. I know the code I have for the export is correct; however, I am getting this error:

RegisterForEventValidation can only be called during Render();

I have done some research and have found a solution, which might work with normal ASPX pages created in VS with a CS code behind class, which is setting the EnableEventValidation to false, and I am getting a Parser error when I attempt to use this solution on my ASPX page.

<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation = "false"%>

Is there any other way to allow this, or any other workaround to my problem using just the ASPX page without the code behind? All of my C# code is within the head and has to be in order for me to run it in my SharePoint environment. 12 hive storage of the CS class is not an option for me. Also, I am not wanting to change anything in my web.config folder if possible.

Thanks

Try creating it as a Web Part - this is the more common approach for this type of scenario in SharePoint.

In SharePoint, all customized pages are run through the Safe Mode Parser which prohibits inline code. Also, this parser does not allow adding controls to pages which have not been marked as "safe".

To get around your issue, you might want to look at "Application Pages" which are added to the \\LAYOUTS directory. They reference the master page and can have inline code, but they can't be customized. They are compiled into a single assembly DLL:

Creating an Application Page in Windows SharePoint Services 3.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM