Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am writing an application that allows users to enrol in something. One web part displays a view of the event calendar and has a button on each event that the user clicks to enrol in the event. A second web part (a DVWP) shows which events the user has currently enrolled in. Enrolments are kept in a separate list.

I want this second DVWP to refresh asynchronously in response to a button click. While I can set the web part to asynchronously refresh periodically, if the web part doesn't refresh quickly enough, it looks to the user like they haven't enrolled at all. I expect the user would try to click the button again. On doing this, they'll receive an error saying that they have already enrolled in this event, which looks wrong as it hasn't shown up in their list of current enrolments.

I've been looking for a method on the DVWP and the SPDataSource called something like Update() that I can call (with JavaScript most likely) that would force the list to be read again. I'm sure I could set the asynchronous refresh interval to 1 second but the penalty would be in extra network traffic and additional reading of the enrolments list server-side.

So is there a way that I can force the list to be read from the client without setting an interval and without requiring a full page postback?

share|improve this question

2 Answers 2

I've used it in a couple occasions in conjunction with jQuery.

I create a hidden span like this after enabling the web part to allow for AJAX updates:

<span style="display:none;">
  <img src="/_layouts/images/staticrefresh.gif" id="ManualRefresh" border="0" onclick="javascript: {ddwrt:GenFireServerEvent('__cancel')}" alt="Click here to refresh the dataview." />
</span>

Then in a jQuery function, I simply do:

$("ManualRefresh").click();

to initiate the DVWP to refresh.

share|improve this answer

Here's a potential workaround/hack that might solve your problem. Instead of trying to have sharepoint do the actual refresh, use jquery. After the user has enrolled do a jquery.get request to the current url. This will have jquery go out and visit the page in a seperate request. Grab the content that would have changed and insert it into your current DOM.

share|improve this answer
    
And here was I thinking I was on my way to another Tumbleweed! I'm thinking this is pretty much what I'm going to have to do. I don't think I can update a dataview from JavaScript at all. It wouldn't be a hack - I'd be using the JavaScript Client OM to refresh a custom UI component. I was thinking that seeing as I'd already done the work on the DataView, I might be able to retrofit an update from the client. Cheers. –  Mike H May 31 '12 at 0:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.