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">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
<SPSWC:pagelevelerror runat="server" id="PageLevelError"/>
<script type="text/javascript">
function update(country) {
//__doPostBack('ContentUpdatePanel', '');
//document.getElementById('aspnetForm').action = "interactivemap.aspx?k=ArticleCountry:" + country;
document.getElementById('ctl00_PlaceHolderFullContent_UpdateButton').click();
}
</script>
<div id="flashFeature">
<object type="application/x-shockwave-flash" data="_layouts/HFT/flashApplets/interactiveMap/interactiveMap/interactiveMapAssets/IMap.swf" width="100%" height="500px" id="flashContent" style="visibility: visible;">
<param name="bgcolor" value="#cccccc"><param name="allowfullscreen" value="true">
<param name="allowscriptaccess" value="always">
<param name="flashvars" value="ASSETS_FOLDER=_layouts/HFT/flashApplets/interactiveMap/interactiveMap/interactiveMapAssets/">
<param na开发者_如何学Pythonme="movie" value="_layouts/HFT/flashApplets/interactiveMap/interactiveMap/interactiveMapAssets/IMap.swf">
<embed src="_layouts/HFT/flashApplets/interactiveMap/interactiveMap/interactiveMapAssets/IMap.swf" width="100%" height="500px"></embed></object>
</div>
<div onclick="update('Romania');">Romania</div>
<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>
</div>
</asp:content>
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
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://tqcblog.com/2007/10/26/creating-a-custom-advanced-search-box-in-moss-2007/
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.
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));
精彩评论