Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.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# 如何将asp:占位符的内容转换为可以应用xml转换的变量?_C#_Asp.net_Asp.net Placeholder - Fatal编程技术网

C# 如何将asp:占位符的内容转换为可以应用xml转换的变量?

C# 如何将asp:占位符的内容转换为可以应用xml转换的变量?,c#,asp.net,asp.net-placeholder,C#,Asp.net,Asp.net Placeholder,如何将asp:占位符的内容转换为可以应用xml转换的变量? 背景 我正在尝试自定义.NET web应用程序的布局。它是一种企业产品,允许我添加/删除ascx文件中的内容块,并更改css属性。我没有访问任何代码隐藏文件(即.cs源代码)的权限,但如果我知道如何将这些文件添加到.ascx文件中,我可能会编写自己的.cs。 但是,实际内容来自应用转换的。 我发现了一些类似的链接(见下文),但我相信这些链接需要访问Codebehind(即.*.cs)文件 问题: 如何将asp:占位符的内容转换为可以

如何将asp:占位符的内容转换为可以应用xml转换的变量?

背景 我正在尝试自定义.NET web应用程序的布局。它是一种企业产品,允许我添加/删除ascx文件中的内容块,并更改css属性。我没有访问任何代码隐藏文件(即.cs源代码)的权限,但如果我知道如何将这些文件添加到.ascx文件中,我可能会编写自己的.cs。 但是,实际内容来自应用转换的
。
我发现了一些类似的链接(见下文),但我相信这些链接需要访问Codebehind(即.*.cs)文件


  • 问题: 如何将asp:占位符的内容转换为可以应用xml转换的变量


    谢谢你的帮助。

    你已经走到一半了。。。您只需要让占位符渲染,然后隐藏结果,对其进行变换,然后渲染变换

    把它放在第二页

    <asp:PlaceHolder ID="TreeHead" runat="server" /><%= FinalTable %>
    
    
    
    在代码背后呈现和转换html

    using (TextWriter stringWriter = new StringWriter())
    {
        using (HtmlTextWriter RenderOnMe = new HtmlTextWriter(stringWriter))
        {
            // render the control
            TreeHead.RenderControl(RenderOnMe);
    
            // transfor here the stringWriter as you like    
    
            // now add it to the string
            FinalTable = "<xml>" + stringWriter.ToString() + "</xml>";
        }
    }
    
    // hide the control, and only render the FinalTable
    TreeHead.Visible = false;
    
    使用(TextWriter stringWriter=new stringWriter())
    {
    使用(HtmlTextWriter renderName=新的HtmlTextWriter(stringWriter))
    {
    //渲染控件
    TreeHead.RenderControl(RenderName);
    //你喜欢的话,就在这儿给这位编剧换吧
    //现在将其添加到字符串中
    FinalTable=“+stringWriter.ToString()+”;
    }
    }
    //隐藏控件,并仅渲染最终表格
    树头可见=假;
    

    FinalTable
    是一个页面
    公共字符串

    ,用于此目的。生成FinalTable的代码是否可以与ID=“TreeHead”的代码位于不同的.cs中,因为我无权访问“TreeHead”的源代码?@kkuilla必须位于保存/呈现该控件的页面上。然而,RenderControl并不总是达到您期望的效果,特别是在复杂的控件上,您需要进行测试。在我的.ascx文件的顶部,它说
    @kkuilla这是一个不同的、可能很复杂的问题。提出一个新的问题。
    
    <div id="loginBox">
    <div class="row">
        <div class="element"><label for="LM_1">Please enter your username</label>  </div>
        <div class="element"><input name="LM$1$" type="text" id="LM_1" />  </div>
    </div>
    <div class="row">
        <div class="element"> <label for="LM_2">Please enter your password</label>       
    </div>
        <div class="element"> <input name="LM$2$" type="password" id="LM_2"/>  </div>
    </div>
    
    <% string table = "<xml>" + <asp:PlaceHolder ID="TreeHead" runat="server"></asp:PlaceHolder> + "</xml>"; %>
    
    <asp:PlaceHolder ID="TreeHead" runat="server" /><%= FinalTable %>
    
    using (TextWriter stringWriter = new StringWriter())
    {
        using (HtmlTextWriter RenderOnMe = new HtmlTextWriter(stringWriter))
        {
            // render the control
            TreeHead.RenderControl(RenderOnMe);
    
            // transfor here the stringWriter as you like    
    
            // now add it to the string
            FinalTable = "<xml>" + stringWriter.ToString() + "</xml>";
        }
    }
    
    // hide the control, and only render the FinalTable
    TreeHead.Visible = false;