Showing posts with label values. Show all posts
Showing posts with label values. Show all posts

Monday, March 26, 2012

instant update from database in aspx page using AJAX

Hi

Can someone point me in the right direction? I have a simple admin screen on my website which shows a tables values from my mssql database. How ever, rather than refreshing every 30 seconds to check for new entries, is there a way using AJAX which instantly updates the admin screen as soon as a new entry is inserted into the database?

thanks

There's not a way for the server to communicate directly with the client, unless the client requests it. The way functionality like what you want is implemented is to continually ping a light weight service that returns information about the last update to the underlying data.

For example, a JSON Web Method that returns the timestamp of the most recent item, which you can compare with the timestamp of the most recent refresh you did. If it's newer than your last update, then you can call a heavier method to update the table.

You can use window.setInterval() in JavaScript to set up the periodic check.


You really have no choice but to set a timer and check the database at a set interval, unless you want to get outside the realm of AJAX and DHTML.

All web based communication is initiated by the client. The only way to have server initiated communication is through an application, such as an AcitveX Object. There are a few (a very few) websites which address this topic but because it is so much more difficult, invasive to the end-users computer, and platform/browser specific, it is rare to find this type of setup.


thanks for your replies, very interesting. I guess the timer option is the way i will have to go. I wish to make the 'service' as light as possible, and the timestamp seems ideal - do you know of any examples, or have any tips on making this as optimal and least processor intensive as possible?

thanks again


You could basically combine these two posts from my blog, with setInterval, to do it:

http://encosia.com/index.php/2007/07/11/why-aspnet-ajax-updatepanels-are-dangerous/

http://encosia.com/index.php/2007/07/13/easily-refresh-an-updatepanel-using-javascript/


thanks gt, great posts - just had a quick browse of the rest of your site, you've got some excellent content on there!!

cheers Yes


I decided to put a simple example together, if anyone else is interested: http://encosia.com/index.php/2007/07/25/display-data-updates-in-real-time-with-ajax/

Saturday, March 24, 2012

Invalid Callback Or Postback Argument

I wrote an ASP.NET 2.0 web page, which populates a drop down list according to the user input values. I put the drop down list into an AJAX UpdatePanel, which is triggered by some server controls. But when I try to run it, the following error prompts out:

Invalid postback or callback argument. Event validation is enabled using <pages enableeventvalidation="true" /> in configuration or <%@dotnet.itags.org. page enableeventvalidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Anybody knows how to solve it?

hello.

can you build a small demo page that reproduces this problem and put it here?

thanks.

Invoking methods

Hello everybody!

I've got a question! We can change property values from XXXXBehavior.js. So can we invoke methods or rise events form XXXXBehavior.js? I mean server side methods!

Thanks:)

Hi again!

I've solve my problem and want to share the solution. i found a way to invoke a serverside method for client script, but it's a reeeeealy ugly way :). The idea is to add to a page another control the supports postback (like LinkButton) and define a OnClick event handler(we will invoke it).

Now the client side function that executes postbacks is "__doPostBack", and we just call it. For example for LinkButton1: "__doPostBack('LinkButton1','');"

Unfortunately i didn't find any other way to solve my problem, so any advices and remarks are welcome.

P.S.

don't forget about UpdatePanles ;)


Consider Client Callbacks, perhaps:http://msdn2.microsoft.com/en-us/library/ms178208.aspx