简体   繁体   English

ASP.NET WebControl返回对象

[英]ASP.NET WebControl Return Object

I am developing a custom tag for asp.net I want to read data from this tag database and return it as a class object and use it on aspx pages. 我正在为asp.net开发自定义标签,我想从此标签数据库中读取数据,并将其作为类对象返回并在aspx页面上使用。

My code: 我的代码:

 private T RenderControl<T>(Control control)
    {
        T test = (T)Convert.ChangeType(GetType(DataSource), typeof(T));
        test = WebFramework.GetSingleData<T>(SQL, SQLParams.ToArray());
        return test;
    }
    protected override void RenderContents(HtmlTextWriter output)
    {
        output.AddAttribute(HtmlTextWriterAttribute.Id, this.ID);
    }

how can I do that? 我怎样才能做到这一点? Example: 例:

<a1:SingleOrDefault ID="test" runat="server" DataSource="MyProject.Models.Members" SQL="SELECT * FROM Members WHERE ID=1"></a1:SingleOrDefault>
<%= test.UserName %>

Thank you. 谢谢。

You could use JSON to convert the object to and from strings, and have your asp.net method work with strings rather than object. 您可以使用JSON在字符串之间来回转换对象,并让asp.net方法使用字符串而不是对象。 JSON can be interpreted in any almost language, server side and client side. JSON可以用几乎所有的语言(服务器端和客户端)来解释。

Example: https://stackoverflow.com/a/2246724/8250558 示例: https//stackoverflow.com/a/2246724/8250558

Netwtonsoft is very popular: https://www.newtonsoft.com/json Netwtonsoft非常受欢迎: https ://www.newtonsoft.com/json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM