Sunday, March 11, 2012

How can display a web form to the user whilst loading data from distributed systems in the

Hi,

I see a potential problem: you can't 'push' data to the browser, it has to be requested. So the thread can finish later but it can't tell the browser to display it at that time. What you can do, is let the browser request the data (maybe in JSON format, or XML) as soon as the page starts to load. Write the script in the beginning of the page, after the MS Ajax scripts are included. You should write it so, that a callback method is called when the asynchronous request is finished. This callback method should put the received data somewhere in the page. I don't believe it is easily binded to (for example) a GridView, so you'd end up writing code to construct a nice view of the data in HTML.

That's my advice, I hope it can help you decide how to work out your control.


Hi,

Thanks for the post. You have pretty much confirmed what I thought after playing with the framework for an hour or so. I will need to pass the details of what data needs fetching to the client, which in turn can call a web service in my app to retrieve the code. I follow the callback Idea - luckily the data will simply say something like 'the text property of textbox1 = "some data from a different system". Therefore presenting the data is simple, as it's just a case of parsing the return data and adding it into field elements in the html of the page.

I'm just a little hazy on the point at which I make the call to fetch the distributed data. Is there some kind of client side event I can hook into to make the request? Like the page load in ASP.NET but client-side? Ideally I'd like to tie this event to the custom control so that if anyone drags it onto their page the event will automatically fire for them.

Thanks in advance

Paul


I guess you could let the control put some javascript in the page when it renders. Depending on how you write the script the browser could start executing the async request as soon as it encounters you scriptblock or you can use the window.onload event to do it when the page has finished loading. Have a look at the Page.ClientScript property, you can use it to manage scripts in a page (as the name suggests ).

Good luck!


Guys, this is easy, and has native support in the framework.

A page w/ a scriptmanager on it automatically calls a pageLoad() funciton if you have one in a .js file (or on the page; ubt in the .js file registered as a scriptreference is best).

On the page:

<form id='form1' runat='server'> <asp:ScriptManager id='sm' runat='server'> <Services> <asp:ServiceReference Path='~/Service.asmx' /> </Services> <Scripts> <asp:ScriptReference path='default.js' /> </Scripts> </asp:ScriptManager><!-- all your other markup --></form>

default.js:

// assumes webservice returns a string, but it doesn't have to.function OnServiceComplete(result){ $get('htmlElementId').innerHTML = result;}function pageLoad(){ Service.methodName(OnServiceComplete);}

Yes, it's just that easy.

Paul

No comments:

Post a Comment