动态控制从Web服务添加到页面 [英] Dynamically add a control to page from a web service
问题描述
我如何得到我的ASP.net web服务控件添加到我的网页,如果我叫webservise从页面加载内?
下面是我的code的一个非常简化的版本。谢谢
''''''''''''''''''页面code后面的'''''''''''''' '''''''''''''''''''''''''''''''''
局部类_Default
继承System.Web.UI.Page 保护小组的Page_Load(BYVAL发件人为对象,BYVAL E上System.EventArgs)把手Me.Load 昏暗米作为新myWebService.Service m.DoThis()
结束小组
末级''''''''''''''''''''''网络服务'''''''''''''''''''''''''' '''''''''''''
进口的System.Web
进口System.Web.Services
进口System.Web.Services.Protocols< WebService的空间(namespace:=http://test.org/)> _
< WebServiceBinding(ConformsTo:= WsiProfiles.BasicProfile1_1)GT; _
&所述; Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
公共服务类
继承System.Web.Services.WebService &所述;的WebMethod()> _
公共职能DoThis()作为字符串
DIM PG作为页= DirectCast(HttpContext.Current.Handler,页) 昏暗txtb作为HtmlButton =新HtmlButton() txtb.InnerText =我卜----- tton pg.Form.Controls.Add(txtb) 返回添加
结束功能末级
一webserivce的工作不是控件的页面。
使用您的web服务,以决定是否某些控件应该被添加到页面,但code将控件添加到页面必须在页面中。
如果是普通code,可以将其添加到一个公共类或一个辅助函数。
想想一个web服务作为一个方法,您可以通过Web调用,参数传递和接收处理的值。
将控件添加到页面并没有真正与Web服务的宗旨顺利。
How do I get my ASP.net webservice to add a control to my page if I call the webservise from inside the page load?
Below is a very simplified version of my code. Thanks
''''''''''''''''''page code behind'''''''''''''''''''''''''''''''''''''''''''''''
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim m As New myWebService.Service
m.DoThis()
End Sub
End Class
''''''''''''''''''''''Web service'''''''''''''''''''''''''''''''''''''''
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://test.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function DoThis() As String
Dim pg As Page = DirectCast(HttpContext.Current.Handler, Page)
Dim txtb As HtmlButton = New HtmlButton()
txtb.InnerText = "my bu-----tton"
pg.Form.Controls.Add(txtb)
Return "added"
End Function
End Class
The job of a webserivce is not to controls to a page.
Use your webservice to decide if some controls should be added to the Page, but the code to add the controls to the Page must be inside the Page.
If it is common code, you can add it to a common class or a helper function.
Think of a webservice as a methods you can call over the web, passing parameters and receiving processed values.
Adding controls to a Page does not really go well with the purpose of a web service.
这篇关于动态控制从Web服务添加到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!