如何在Web服务中引发事件以动态创建控件 [英] How to Raise events for dynamically Created control in a Web Serive

查看:89
本文介绍了如何在Web服务中引发事件以动态创建控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用一个名为SearchBox.dll的dll,它将使用MSNWebService在整个网站中进行搜索并向我返回结果.



http://www.asp.net/community/control-gallery/Item.aspx?i=1419

我想在Web服务中使用它.

这是我的代码


使用ControlFreak;
[WebMethod(EnableSession = true)]
公共无效的CallWebService()
{
试试
{

SearchBox objSB = new SearchBox();
objSB.SearchProvider = SearchBox.SearchProviderEnum.MSNWebService;

objSB.ShowSearchOptions = false;
objSB.SearchSite ="www.dell.com";
objSB.SearchSiteOnly = true;
objSB.Search("laptop");
objSB.SearchResultsReady + =新的SearchBox.SearchResultsReadyEventHandler(objSB_SearchResultsReady);
}

catch(ex ex例外)
{
字符串str = ex.Message;
}


}

void objSB_SearchResultsReady(DataTable SearchResults)
{
DataTable dt = new DataTable();
dt = SearchResults;
}


有人可以告诉我如何引发事件objSB_SearchResultsReady

在此先感谢

Hi,

I am using a dll called SearchBox.dll which will search across web sites using MSNWebService and return me the results.



http://www.asp.net/community/control-gallery/Item.aspx?i=1419

i want to use this in a web service.

here is my code


using ControlFreak;
[WebMethod(EnableSession = true)]
public void CallWebService()
{
try
{

SearchBox objSB = new SearchBox();
objSB.SearchProvider = SearchBox.SearchProviderEnum.MSNWebService;

objSB.ShowSearchOptions = false;
objSB.SearchSite = "www.dell.com";
objSB.SearchSiteOnly = true;
objSB.Search("laptop");
objSB.SearchResultsReady += new SearchBox.SearchResultsReadyEventHandler(objSB_SearchResultsReady);
}

catch (Exception ex)
{
string str = ex.Message;
}


}

void objSB_SearchResultsReady(DataTable SearchResults)
{
DataTable dt = new DataTable();
dt = SearchResults;
}


Can somebody please tell me how to raise the event objSB_SearchResultsReady

thanks in advance

推荐答案

通常这不会有问题,只需在Event上调用.Invoke,但是我看到您使用的是非标准的事件处理程序.所有事件处理程序都应继承自System.EventHandler,并应处理继承自System.EventArgs的参数.实际上,这意味着您可以使用Generics EventHandler< t>.而不是编写自己的类.
Normally this would not be a problem, just call .Invoke on the Event, however I see you are using a non standard eventhandler. All eventhandlers should inherit from System.EventHandler and should handle arguments that inherit from System.EventArgs. In fact that would mean you can use the Generics EventHandler<t> and not write your own class.


这篇关于如何在Web服务中引发事件以动态创建控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆