Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute server side code without full postback

When a user clicks a button I need to create a .bmp file on the server. After the .bmp file is created I will load it into the html page. Would Ajax be the best way to accomplish this?

like image 209
fpz Avatar asked Aug 25 '26 00:08

fpz


1 Answers

Yes AJAX is the best way. It can be done through ASP.NET's AJAX mechanisms, jQuery itself or another of your choice.

If you're just generating an image for return to the browser then instead of invoking an ASP.NET page (.aspx) lifecycle for it, use the lighter HTTP handler (.ashx). Here's an example on the server-side.

(The HTTP Handlers work by inheriting your class from something like DefaultHttpHandler or implementing IHttpHandler instead of the Page class.)

Additional Samples and notes about AJAX communication:

  • If you choose an ASPX Page to generate your image, then use WebMethod attributes on page methods to facilitate AJAX communication with them; or an explicit .ASMX Web Service to do the same using the WebMethod attribute.
    or,
  • ASP.NET AJAX and HTTP Handlers
  • You can pick up many tidbits from Stackoverflow for example, you don't need an ASPX or ASHX page, just a raw class that inherits IHttpHandler and web.config httphandler settings in place to make it work.

To debug this kind of stuff it's very useful to have an HTTP Monitoring utility like Fiddler to watch the out-of-band HTTP requests and responses.

like image 171
John K Avatar answered Aug 26 '26 13:08

John K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!