Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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
什么';将复杂数据传递到ASP.Net控件的最佳方法是什么?_Asp.net_Xml_Controls - Fatal编程技术网

什么';将复杂数据传递到ASP.Net控件的最佳方法是什么?

什么';将复杂数据传递到ASP.Net控件的最佳方法是什么?,asp.net,xml,controls,Asp.net,Xml,Controls,我想把复杂的信息传递给控件。相当于整个XML文档。实现这一目标的最佳方式是什么: <MyPrefix:MyControl runat="server"> <Actions> <Action Name="Value" SomeParam="SomeValue" AnotherParam="AnotherValue"/> <Action Name="Value"/> </Action> </MyPrefix:M

我想把复杂的信息传递给控件。相当于整个XML文档。实现这一目标的最佳方式是什么:

<MyPrefix:MyControl runat="server">
  <Actions>
    <Action Name="Value" SomeParam="SomeValue" AnotherParam="AnotherValue"/>
    <Action Name="Value"/>
  </Action>
</MyPrefix:MyControl>

我是否可以将“Actions”属性作为字符串,然后将其内容包装在根标记中并将其解析为XML


这里有关于最佳实践的指导吗?

您可以添加类似
XmlFileName
的属性,并在需要时读取相关文件。

啊哈,明白了吗

using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing.Design;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;

namespace Unknown
{

    public class TestBuilder : ControlBuilder
    {

        public override bool AllowWhitespaceLiterals()
        {
            return false;
        }

        public override bool HtmlDecodeLiterals()
        {
            return true;
        }

    }

    [ToolboxData("<{0}:Test runat=\"server\" />"), DefaultProperty("Actions"), ParseChildren(true, "Actions"), ControlBuilder(typeof(TestBuilder))]
    public class Test : WebControl
    {

        [PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty), Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]
        public string Actions { get; set; }

        protected override void OnLoad(System.EventArgs e)
        {
            XDocument doc = XDocument.Parse("<Actions>" + this.Actions + "</Actions>");

            base.OnLoad(e);
        }

    }

}
使用System.ComponentModel;
使用System.ComponentModel.Design;
使用系统、绘图、设计;
使用System.Web.UI;
使用System.Web.UI.WebControl;
使用System.Xml.Linq;
名称空间未知
{
公共类TestBuilder:ControlBuilder
{
public override bool AllowWhitespaceLiterals()
{
返回false;
}
公共覆盖bool HtmlDecodeLiterals()
{
返回true;
}
}
[ToolboxData(“”)、DefaultProperty(“操作”)、ParseChildren(true,“操作”)、ControlBuilder(typeof(TestBuilder))]
公共类测试:网络控制
{
[PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty)、编辑器(typeof(MultilineEditor)、typeof(UITypeEditor))]
公共字符串操作{get;set;}
受保护的覆盖无效OnLoad(System.EventArgs e)
{
XDocument doc=XDocument.Parse(“+this.Actions+”);
基础荷载(e);
}
}
}

No,因为我已经为这个控件的每个具有不同参数的实例管理了一个单独的文件。哇,做得很好。事实上,我最终使用了子控件,每个子控件映射到一个类,这真的非常巧妙。出色的工作。