Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
';写作';C#SharePoint Web部件中的HTML代码_C#_Html_Sharepoint - Fatal编程技术网

';写作';C#SharePoint Web部件中的HTML代码

';写作';C#SharePoint Web部件中的HTML代码,c#,html,sharepoint,C#,Html,Sharepoint,我正试图找到一种方法,可以用C#将html代码写入SharePoint Web部件。我甚至不知道这是否可能,但我认为是的。在JavaScript中,它只是类似于document.write(“”+variable+”)的东西,所以我只是想弄清楚这在C#中是如何工作的。有一个比这更大的画面,但这是我坚持的基本部分 我希望HTML代码位于下面的for循环中 代码如下: using System; using System.Web.UI; using System.Web.UI.WebControls

我正试图找到一种方法,可以用C#将html代码写入SharePoint Web部件。我甚至不知道这是否可能,但我认为是的。在JavaScript中,它只是类似于
document.write(“
”+variable+”)
的东西,所以我只是想弄清楚这在C#中是如何工作的。有一个比这更大的画面,但这是我坚持的基本部分

我希望HTML代码位于下面的for循环中

代码如下:

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using System.Web;

namespace CSharpAttempt.VisualWebPart1
{

public class getTheSPItems
{
    public void Page_Load(object sender, EventArgs e)
    {
        int i;

        for (i = 0; i <= 10; i++)
        {
            string theHtmlString = "<b>" + i + "</b>";
            Response.Write(theHtmlString);

        }
    }
}



public partial class VisualWebPart1UserControl : UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}
}
使用系统;
使用System.Web.UI;
使用System.Web.UI.WebControl;
使用System.Web.UI.WebControl.WebParts;
使用Microsoft.SharePoint;
使用Microsoft.SharePoint.Utilities;
使用System.Web;
命名空间CSharpTest.VisualWebPart1
{
公共类获取这些资源
{
公共无效页面加载(对象发送方,事件参数e)
{
int i;
对于(i=0;i简单答案

Response.Write (theHtmlString);




如果要将其添加到页面的特定部分,请将文字控件拖到Web窗体上

使用

答案很简单

Response.Write (theHtmlString);




如果要将其添加到页面的特定部分,请将文字控件拖到Web窗体上

使用


是的,你可以。如果你把一个ASP.Net控件放在页面上并给它一个ID,你可以在代码中非常简单地引用它

请参阅此堆栈溢出回答:


编辑:查看此新的SO,了解基本ASP.Net表单操作的答案

是的,您可以。如果您在页面上放置ASP.Net控件并给它一个ID,您可以在代码中非常简单地引用它

请参阅此堆栈溢出回答:


编辑:查看此新的SO,了解基本ASP.Net表单操作的答案

SharePoint Web部件只是一个ASP.Net控件

通过添加到控件集合,您可以向其中添加任何其他SharePoint控件、WebControl或html

this.Controls.Add(new HtmlGenericControl("div") { InnerText ="My HTML"});

SharePoint Web部件只是一个ASP.NET控件

通过添加到控件集合,您可以向其中添加任何其他SharePoint控件、WebControl或html

this.Controls.Add(new HtmlGenericControl("div") { InnerText ="My HTML"});

是的,我想不出这个响应。写出来。每次我尝试使用它时,我都会得到一个错误:“响应”这个名称在当前文件中不存在context@mwilson添加system.web,我只看到system.web.ui是的,我无法理解此响应。请写出。每次尝试使用它时,我都会收到一个错误:“响应”名称在当前文件中不存在context@mwilsonA.dd system.web,我只看到system.web.ui谢谢。你能给我一个更好的例子吗?在你的VisualWebPart1UserControl类中,在页面_Load()中方法,您将添加上面的代码段。我不确定getTheSPItems类的用途-根据上面的代码根本不会调用该类。错误1找不到类型或命名空间名称“HtmlGenericControl”(您是否缺少using指令或程序集引用?)c:\users\administrator\documents\visualstudio 2010\Projects\csharptrest\csharptrest\VisualWebPart1\VisualWebPart1UserControl.ascx.cs 32 35 CSharpAttemptadd使用
System.Web.UI.HtmlControls;
添加到cs文件中。
this.Response.Write(“我的html”)
谢谢。你能给我一个更好的例子吗?在你的VisualWebPart1UserControl类中,在Page_Load()方法中,你会添加上面的代码段。我不确定你的getTheSPItems类是做什么的-根据你上面的代码根本不会调用它。错误1找不到类型或命名空间名称“HtmlGenericControl”(您是否缺少using指令或程序集引用?)c:\users\administrator\documents\visual studio 2010\Projects\CSharpTest\CSharpTest\VisualWebPart1\VisualWebPart1UserControl.ascx.cs 32 35 CSharpAttemptAddUsing
System.Web.UI.htmlControl;
添加到您的cs文件中。
this.Response.Write(“我的html”)