views:

410

answers:

3

Hi Guys,

Been tearing my hear out with this one. Let me see if I can explain:

I have a SharePoint results page on which I have a Search Results Core WebPart. Now I want to change the parameter in the querystring when I postback the page so that the WebPart returns different results for each parameter e.g. the querystring will be interactivemap.aspx?k=Country:Romania this will filter the results for Romania.

First issue is I want to do this with javascript so I call:

document.getElementById('aspnetForm').action = "interactivemap.aspx?k=Country:" + country;

Nothing special here but the reason I need to call from Javascript is there is also a flash applet on this page from which the Javascript calls originate. When the javascript calls are made the page needs to PostBack but not reload the flash applet.

I turned to ASP.Net AJAX for this so I wrapped the search results webpart in an update panel. Now if I use a button within the UpdatePanel to postback the UpdatePanel behaves as expected and does a partial render of the search results webpart not reloading the flash applet.

Problem comes because I need postback the page from javscript. I called __doPostBack() as I have used this successully in the past. It works on it's own but fails when I first call the above Javascript before the __doPostBack() (I also tried calling click() on a hidden button) the code for the page is at the bottom.

I think the problem comes with the scriptmanager not allowing a partial render when the form post action has changed.

My questions are.

A) Is there some other way to change the search results webpart parameter without using the querystring.

or

B) Is there a way around changing the querystring when doing an AJAX postback and getting a partial render.

<asp:Content ContentPlaceHolderID="PlaceHolderFullContent" runat="server">

function update(country) { //__doPostBack('ContentUpdatePanel', ''); //document.getElementById('aspnetForm').action = "interactivemap.aspx?k=ArticleCountry:" + country; document.getElementById('ctl00_PlaceHolderFullContent_UpdateButton').click(); }

Romania
   <div class="firstDataTitle">
  <div class="datatabletitleOuterWrapper">
      <div class="datatabletitle">
          <span>Content</span></div>
  </div>
     <div class="datatableWrapper">
         <div class="dataHolderWrapper">
             <div class="datatable">
                 <div>
                    <div class="searchMain">          
                        <div class="searchZoneMain">
                         <asp:UpdatePanel runat="server" id="ContentUpdatePanel"  UpdateMode="Conditional">                              
     <ContentTemplate>
      <WebPartPages:webpartzone runat="server" AllowPersonalization="false" title="<%$Resources:sps,LayoutPageZone_BottomZone%>" id="BottomZone" orientation="Vertical" QuickAdd-GroupNames="Search" QuickAdd-ShowListsAndLibraries="false"><ZoneTemplate></ZoneTemplate></WebPartPages:webpartzone>
      <asp:Button id="UpdateButton" name="UpdateButton" runat="server" Text="Update"/>
      </ContentTemplate>
    </asp:UpdatePanel>

                        </div>
                    </div>    
                </div>                        
         </div>                           
     </div>
 </div>

A: 

Hi Lee,

I would suggest to get rid of the UpdatePanel. A much better way would be to use "proper" ajax e.g. with jQuery and update your web part data based on the retrieved data.

As you have noticed the UpdatedPanel is usually just a quick implementation that has got its limitations. However, I can't think of a good reason to justify the overhead that it comes with.

Michael

Michael Ulmann
+1, for the statement `A much better way would be to use "proper" ajax e.g. with jQuery` :-)
Darin Dimitrov
Hehe thanks. There are still a lot of ppl who believe that the MS UpdatePanel solution is proper AJAX.
Michael Ulmann
That would be a much better way if not trying to use SharePoint components. SharePoint likes the update panel, and trying to fight the way SharePoint does things is a really bad idea.
Tom Clarkson
Hi Guys,Thanks for your answers but I don't think jquery will help me here, as I'm dealing with the search results webparts and I need a full postback but just partial rendering. But it may be something I look at if im out of options.
Lee Dale
+1  A: 

The search results web part also accepts queries in a posted form - the advanced search box does not set the query string.

You can find the relevant field names on my blog - http://www.tqcblog.com/archive/2007/10/26/creating-a-custom-advanced-search-box-in-moss-2007.aspx

Using that approach you should be able to return to your original test of using a button within the update panel. You may even be able to use the standard advanced search box (with most fields turned off) inside the update panel.

Remember that posted fields and rendered controls are pretty much the same thing, and that the type of control doesn't matter - you can add one of the text boxes from the advanced search box as a hidden field, inside the update panel with your button. That way it's just a standard form inside an update panel.

Tom Clarkson
A: 

This comes close to an answer for me, but your article didn't specify the posted fields just the fields that the advanced search webpart renders. I'm not using any input fields to specify the query just a javascript call.

I tried using the following code which gets me closer but the problem is it all works but won't do a partial render when the JS is called. I have no idea why as I'm specifiying the eventTarget as a button ID which is a child of the updatepanel.

Im using:

WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$PlaceHolderFullContent$UpdateButton", "", false, "", "interactivemap.aspx?k=ArticleCountry:" + country, false, true));
Lee Dale
This should probably be a comment rather than an answer - I have edited my original answer to clarify.
Tom Clarkson
Ok I see what your saying and I might have to use this if I can't find out why my solution doesn't work.I'm quite intrigued as to why the partial render doesn't happen with the above code. I know the eventTarget is right, but it seems because the post action has changed to include a querystring it stops the partial render from happening. Can anyone explain why?
Lee Dale