I have a button on a web form and when I click it my code executes but in order for any changes to occur the page has to ref开发者_JAVA百科resh itself. How do I make the changes happen without a refresh?
You'd probably have to use Ajax
Since you're using asp.net webforms, you could most easily place the code needed to be updated asynchronously into an UpdatePanel
Slightly more challenging, but more robust, you could also put your code into web services (or static page methods, I believe) and then use jQuery
to call them, and use the results from them to update your dom.
Just one small note on the jQuery option, since, as another answerer has noted, I could be typing all day, make sure you don't use dom ids to select your dom elements for update, since asp.net messes with the ids that are actually generated (unless you're using asp.net 4, where this is configurable)
jQuery homepage
UpdatePanel Tutorial
Question on calling asmx with jQuery
Regular asp.net web forms are dependent on the post back cycle of web. You'll need to use some AJAX (asynchronous javascript and xml) controls in order to get some actions to occur asynchronously on your web page. Google for ASP.NET AJAX and you'll find what you're looking for. Here are some links to get you started:
Download Ajax
Tutorial
Its called AJAX. JavaScripts on the client contact the page, often reading data to update the HTML-page. For instance for a progress indicator to update.
Just set up a timer on the page and do whatever required in the server codebehind.
For some tutorials on how to get started look here: https://stackoverflow.com/questions/257110/ajax-tutorial
精彩评论