Sharepoint 代码隐藏中页面布局的访问控件

Sharepoint 代码隐藏中页面布局的访问控件,sharepoint,layout,Sharepoint,Layout,我正在SharePoint中开发一个发布门户。页面布局和母版页是使用VisualStudio设计的,我使用wspbuilder将页面布局部署到内容数据库中 我有一个要求,其中我必须访问代码隐藏中的页面布局控件,并向控件分配或从控件获取值。但是,VS intellisense从未显示我的页面布局中使用的控件。我应该怎么做才能使用代码隐藏访问控件 有什么解决办法吗 问候,, Raghuraman.V您必须公开用户控件上的web控件 下面是一个快速示例,演示如何从父页面更改用户控件的文本框: WebU

我正在SharePoint中开发一个发布门户。页面布局和母版页是使用VisualStudio设计的,我使用wspbuilder将页面布局部署到内容数据库中

我有一个要求,其中我必须访问代码隐藏中的页面布局控件,并向控件分配或从控件获取值。但是,VS intellisense从未显示我的页面布局中使用的控件。我应该怎么做才能使用代码隐藏访问控件

有什么解决办法吗

问候,,
Raghuraman.V

您必须公开用户控件上的web控件

下面是一个快速示例,演示如何从父页面更改用户控件的文本框:

WebUserControl1.ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication1.WebUserControl1" %>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
WebForm1.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<%@ Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">       
        <uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
    </div>
    </form>
</body>
</html>

我猜你在两个不同的项目中或者至少在两个不同的位置有页面布局和代码。您还可以在SharePoint中使用与ASPX文件并排的“真实”代码隐藏页面,这样就不必重新声明控件

为此,可以将WSP包的Visual Studio项目创建为 “ASP.NET Web应用程序”,使用代码隐藏文件并排创建ASPX页面并使用WSP Builder从包中删除C#文件(代码仍编译到程序集中并与之一起部署)。这个技巧很有效,因为WSP生成器可以 在Visual Studio项目中配置了本地配置文件以删除某些文件 类型

这里是本地WSPBuilder.exe.config文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <appSettings>
  <add key="Excludefiletypes" value="cs" />
 </appSettings>
</configuration>


@Bernd,当我将文本框更改为受保护而不是公共时,我收到一个错误,提示WebApplication1.WebUserControl1.UserControlTextBox1由于其保护级别而无法访问。抱歉-我没有正确阅读您的代码。当然,您不能从另一个类访问受保护的属性-我的错误。我的意思是,您可以通过在WebUserControl1.ascx.cs中声明受保护的控件来访问代码中的控件,而不是声明公共属性,例如:受保护的TextBox TextBox1;
using System;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            WebUserControl11.UserControlTextBox1.Text = "Your text here...";
        }
    }
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <appSettings>
  <add key="Excludefiletypes" value="cs" />
 </appSettings>
</configuration>