简体   繁体   English

从SharePoint到Excel ASPX的GridView

[英]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. 我有一个正在SharePoint中运行的ASPX文件,该文件具有一个GridView,试图将其导出到Excel电子表格中。 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. 我进行了一些研究,找到了一个解决方案,该解决方案可能与在VS中创建的普通ASPX页面一起工作,并且在类后面带有CS代码,这将EnableEventValidation设置为false,并且在尝试使用此解决方案时出现解析器错误在我的ASPX页面上。

<%@ 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? 是否有其他方法可以解决此问题,或者仅使用ASPX页而不使用任何代码即可解决我的问题? All of my C# code is within the head and has to be in order for me to run it in my SharePoint environment. 我所有的C#代码都在头部,必须在我的SharePoint环境中运行它。 12 hive storage of the CS class is not an option for me. 对我来说,CS类的12个配置单元存储不是一个选择。 Also, I am not wanting to change anything in my web.config folder if possible. 另外,如果可能的话,我也不想更改web.config文件夹中的任何内容。

Thanks 谢谢

Try creating it as a Web Part - this is the more common approach for this type of scenario in SharePoint. 尝试将其创建为Web部件-这是SharePoint中这种情况下更常见的方法。

In SharePoint, all customized pages are run through the Safe Mode Parser which prohibits inline code. 在SharePoint中,所有自定义页面均通过安全模式解析器运行,该模式禁止内联代码。 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. 要解决您的问题,您可能需要查看添加到\\ LAYOUTS目录中的“应用程序页面”。 They reference the master page and can have inline code, but they can't be customized. 它们引用母版页,可以具有内联代码,但不能自定义。 They are compiled into a single assembly DLL: 它们被编译成单个程序集DLL:

Creating an Application Page in Windows SharePoint Services 3.0 在Windows SharePoint Services 3.0中创建应用程序页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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