简体   繁体   English

在Ajax WCF服务中加载用户控件并访问自定义属性

[英]Load a User Control in an Ajax WCF Service and Access Custom Properties

I can load a generic user control just fine in my WCF service doing the following: 我可以在WCF服务中很好地加载通用用户控件,执行以下操作:

UserControl userControl= (UserControl) new Page().LoadControl("~/UserControls/MyControl.ascx");

However i can't seem to find any way to do this 但是我似乎找不到任何办法

MyControl myControl=(MyControl)userControl;

The reason i need to do this is because my user control has a custom property, person, I need to do the following: 我需要执行此操作的原因是因为我的用户控件具有自定义属性,所以我需要执行以下操作:

myControl.Person=new Person();

essentially i need to simulate: 本质上我需要模拟:

<%@ Reference Control="~/UserControls/MyControl.ascx" %>

which normally goes inside asp.net page or master-pages. 通常放在asp.net页或母版页中。

any way of doing this in an Ajax Enabled WCF Service? 在启用Ajax的WCF服务中执行此操作的任何方法?

You should not be passing user controls to a service, period. 您不应将用户控件传递给服务期限。 Please read up on separation of concerns and dependency injection design patterns, to find out why. 请仔细阅读关注点分离依赖注入设计模式,以找出原因。

I found a way around this. 我找到了解决方法。 A better way doing this is to simply use page methods instead of a WCF service. 更好的方法是简单地使用页面方法而不是WCF服务。

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

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