in asp.net WebService, passing a WebControl to a WebMethod

房东的猫 提交于 2019-12-11 15:23:18

问题


I'm using asp.net 4 ,C# ,VS 2010. I'm facing a problem by calling a web service method which has a WebControl as a parameter.

/// <summary>
/// Summary description for FormsViews
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]

public class FormViews : System.Web.Services.WebService
{
    [WebMethod]
    public void SetCaption(System.Web.UI.WebControls.Button bt)
    {
        //Code...
    }
}

It compiles with no errors. On RunTime I get this message:

The XML element 'EnableTheming' from namespace 'namespace' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the element.

Can you please explain why the webService doesn't accept a WebControl and how to handle this issue?


回答1:


The web service does not accept a WebControl because it is not serializable and good web service design does not directly manipulate views or user interfaces. Logic for your views should be left in your views, not in what is typically the business layer. A typical way to handle language support in a view or web page is to make a request to a web service that indicates the language the page should support and it returns a list of labels as key/value pairs. The key is an ID for the control and the value is what should be displayed in the control. This is only necessary if your web page uses a lot of Ajax. If you are just rendering the page on the server then you can populate the controls with the correct language when they are rendered on the server. Here is an MSDN article that discusses how to do this.



来源:https://stackoverflow.com/questions/12492748/in-asp-net-webservice-passing-a-webcontrol-to-a-webmethod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!