让代码在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>

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值