LA.NET [EN]

May 03

AJAX ASP.NET May future bits: there are also new things here!

Posted in ASP.NET MS AJAX      Comments Off on AJAX ASP.NET May future bits: there are also new things here!

With all this excitment around Silverlight, I”ve been negleted the new things that have appeared on the AJAX May future bits. 10 minutes ago I”ve just discovered that the team is implementing some sort of search service that you can plug in through the config file. Currently, and as you might expect from a beta build, some things aren”t still ready, but i think the basic idea is there: there”s a new kind of provider (SearchProviderBase) which currently only has one concrete implementation: the WindowsLiveSearchProvider class.

This provider uses the MSN web search service to perform its search. Currently, it”s functionalities are very limited since you can only sent a query and indicate one domain to filter the results of your search. As you minght expect, there”s a SearchDataSource control too. It”s really a specialization of the ObjectDataSource control and if you drop it on the designer, you”ll still have to set up the parameter (of type string) which is expected by the Search method.

Lets write a quick example that shows how you can use these new classes. After droping the preview bits dll on the bin folder, you have to add the following to the <microsoft.web.preview> section group on the web config file:

<search enabled=”true”>
  <providers>
      <add name=”WindowsLiveSearchProvider” 
           type=”Microsoft.Web.Preview.Search.WindowsLiveSearchProvider,
            Microsoft.Web.Preview”
          appID=”F8A1EE74E4CD75A9D1B542287A9D868185518B5F” siteDomainName=””/>
  </providers>
</search>

This is necessary in order to configure the search provider that should be used by default. Note that the siteDomainName is set to an empty string. If you wanted to get only hits from, say, Microsoft,you could set it to microsoft.com. Building a demo page on top of this provider is easy,as the following snippet shows:

<asp:TextBox runat=”server” ID=”query” />
<asp:Button runat=”server” ID=”bt” Text=”Pesquisar” />

<asp:GridView runat=”server” ID=”myGrid”
  datasourceid=”mySource”
  AutoGenerateColumns=”false”>
  <Columns>
    <asp:BoundField HeaderText=”Titulo” DataField=”Title” />
    <asp:BoundField HeaderText=”Url” DataField=”Url” />
    <asp:BoundField HeaderText=”Descrição” DataField=”Description” />
  </Columns>
</asp:GridView>
<asp:SearchDataSource ID=”mySource” runat=”server”>
  <SelectParameters>
    <asp:ControlParameter Name=”query” Type=”String” ControlID=”query” />
  </SelectParameters>
</asp:SearchDataSource>

And that”s it! We add a control parameter so that the SearchDataSource is automatically fed from the value entered on the textbox. If you run this page, you might get disapointed because you”ll only get 10 results (or something like that). Currently, I think there isn”t any property that lets you set the number of elements that you want to get from the search (btw, you couldn”t get more than 50 elems per service method call…). If you think that you can add paging to this control, you”re wrong! currently, it”s not supported.

Now, when I found this control i was really surprised because I”ve spent some hours during a couple of days building a data source that is responsible for using the MSN search service 🙂 In fact, I”ll be publishing the code in the next days and some videos (in PT – well, trust me: you do not want to hear me speak english after not doing it for more than 10 years 🙂 ) that explain what the controls do and how I”ve built it…