• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
虾米成长的园子
博客园    首页    新随笔    联系   管理    订阅  订阅
让代码在SharePoint页面执行&&如何在aspx页面中写代码

SharePoint 2007 版本开始支持 .aspx 嵌入内联代码,但此项功能默认是关闭,可以再 web.config 的 SharePoint/SafeMode/PageParserPaths 配置节进行配置,如 
<PageParserPaths>        <PageParserPath VirtualPath="/pages/hello.aspx" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true"/></PageParserPaths> 
还可以用通配符 
<PageParserPaths>        <PageParserPath VirtualPath="/pages/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true"/></PageParserPaths> 
其中 CompilationMode 可用值包括:Always      The page should always be compiled (default value) Auto        ASP.NET will not compile the page, if possible.  Never       The page or control should never be dynamically compiled. 
基于安全的考虑,最好不要对所有文件开启此项功能。因为任何具有修改页面的权限的用户有可能天健恶意代码。

 


今天,要在人家原来的系统上加个独立的功能页面,没有原代码的,所以只能把c#的后台代码写在aspx页面上,但是各控件的事件等让我犯难了,要怎么写呢?
   原来,其实跟写后台代码一样写,把设计器生成代码也copy过去,委托什么的一样写,还挺方便的,如下面:
<script language="c#" runat="server">
#region Page_Load   private void Page_Load(object sender, System.EventArgs e)   {
    ……

    if(!Page.IsPostBack)    {……}

   }   #endregion
   #region Web Form Designer generated code   override protected void OnInit(EventArgs e)   {    //    // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。    //    InitializeComponent();    base.OnInit(e);   }     /// <summary>   /// 设计器支持所需的方法 - 不要使用代码编辑器修改   /// 此方法的内容。   /// </summary>   private void InitializeComponent()   {        this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);    this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);    this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);    this.FSDataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.FSDataGrid1_ItemDataBound);    this.Load += new System.EventHandler(this.Page_Load);
   }   #endregion
private void btnAdd_Click(object sender, System.EventArgs e)   {……}
private void btnSearch_Click(object sender, System.EventArgs e)   {……}
</script>

 

posted on 2010-11-19 17:25  残影  阅读(507)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3