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?
当用户单击按钮时,我需要在服务器上创建.bmp文件。创建.bmp文件后,我将它加载到html页面。 Ajax是实现这一目标的最佳方式吗?
6 个解决方案
#1
4
Yes AJAX is the best way. It can be done through ASP.NET's AJAX mechanisms, jQuery itself or another of your choice.
是的,AJAX是最好的方式。它可以通过ASP.NET的AJAX机制,jQuery本身或您自己选择的其他方式来完成。
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.
如果您只是生成一个图像以返回到浏览器,那么不要为它调用ASP.NET页面(.aspx)生命周期,而是使用较轻的HTTP处理程序(.ashx)。这是服务器端的一个例子。
(The HTTP Handlers work by inheriting your class from something like DefaultHttpHandler or implementing IHttpHandler instead of the Page class.)
(HTTP处理程序通过从DefaultHttpHandler继承您的类或实现IHttpHandler而不是Page类来工作。)
Additional Samples and notes about AJAX communication:
有关AJAX通信的其他示例和说明:
- 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 * 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.
如果您选择ASPX页面来生成图像,那么在页面方法上使用WebMethod属性来促进与它们的AJAX通信;或使用WebMethod属性执行相同的.ASMX Web服务。要么,
ASP.NET AJAX和HTTP处理程序
例如,您可以从*中获取许多花絮,您不需要ASPX或ASHX页面,只需要继承IHttpHandler和web.config httphandler设置的原始类来使其工作。
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.
要调试这种东西,让Fiddler等HTTP监控实用程序观察带外HTTP请求和响应非常有用。
#2
2
Short answer: Yes.
简短回答:是的。
ajax would be the best way to do this. Look at the jquery docs to start with. Its not really that simple of a thing to do and doesn't lend itself to posting a snippet to illustrate. You're going to have to get cozy with several possibly new concepts here.
ajax将是最好的方法。查看jquery文档开头。它不是那么简单的事情,也不适合发布一个片段来说明。你将不得不在这里熟悉几个可能的新概念。
http://docs.jquery.com/Main_Page
Here's the direct link to jQuery's ajax documentation.
这是jQuery的ajax文档的直接链接。
http://api.jquery.com/category/ajax/
If you've never done jQuery, its kinda weird, but definitely worth taking the time to get used to.
如果你从来没有做过jQuery,它有点奇怪,但绝对值得花时间去习惯。
#3
1
One side-note. Do you really need to output a BMP file to display it in the HTML?
一个侧面说明。你真的需要输出一个BMP文件来在HTML中显示它吗?
BMPs are quite heavy and uncompressed, if you must store it in that format serer-side, maybe you can also save a JPG "thumbnail" and output that. It will be much faster, whenever you decide to use AJAX or normal postbacks.
BMP非常繁重且未压缩,如果你必须将它存储在那个格式的serer端,也许你也可以保存JPG“缩略图”并输出它。每当您决定使用AJAX或普通回发时,它会快得多。
As everyone else said, AJAX is the best approach because response will be much smaller (just the contents) than returning the full page.
正如其他人所说,AJAX是最好的方法,因为响应将比返回整页更小(只是内容)。
Also for debugging, apart from Fiddler I like to use Firefox with Firebug, it is an excellent web development tool.
另外,对于调试,除了Fiddler我喜欢使用Firefox和Firebug,它是一个优秀的Web开发工具。
#4
0
if you don't want a full post back, yes.
如果你不想要一个完整的帖子,是的。
#5
0
if you want to provide an useful feature on this then you should go Ajax if not then a postback is OK
如果你想提供一个有用的功能,那么你应该去Ajax,如果没有,那么回发是好的
#6
0
You don't have to use Ajax. You can set your page to AutoEventWireUp="false" and handle all events by hand. Circumvent the Page_Load event on the Button click and voila.
您不必使用Ajax。您可以将页面设置为AutoEventWireUp =“false”并手动处理所有事件。绕过Button上的Page_Load事件并点击瞧。
#1
4
Yes AJAX is the best way. It can be done through ASP.NET's AJAX mechanisms, jQuery itself or another of your choice.
是的,AJAX是最好的方式。它可以通过ASP.NET的AJAX机制,jQuery本身或您自己选择的其他方式来完成。
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.
如果您只是生成一个图像以返回到浏览器,那么不要为它调用ASP.NET页面(.aspx)生命周期,而是使用较轻的HTTP处理程序(.ashx)。这是服务器端的一个例子。
(The HTTP Handlers work by inheriting your class from something like DefaultHttpHandler or implementing IHttpHandler instead of the Page class.)
(HTTP处理程序通过从DefaultHttpHandler继承您的类或实现IHttpHandler而不是Page类来工作。)
Additional Samples and notes about AJAX communication:
有关AJAX通信的其他示例和说明:
- 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 * 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.
如果您选择ASPX页面来生成图像,那么在页面方法上使用WebMethod属性来促进与它们的AJAX通信;或使用WebMethod属性执行相同的.ASMX Web服务。要么,
ASP.NET AJAX和HTTP处理程序
例如,您可以从*中获取许多花絮,您不需要ASPX或ASHX页面,只需要继承IHttpHandler和web.config httphandler设置的原始类来使其工作。
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.
要调试这种东西,让Fiddler等HTTP监控实用程序观察带外HTTP请求和响应非常有用。
#2
2
Short answer: Yes.
简短回答:是的。
ajax would be the best way to do this. Look at the jquery docs to start with. Its not really that simple of a thing to do and doesn't lend itself to posting a snippet to illustrate. You're going to have to get cozy with several possibly new concepts here.
ajax将是最好的方法。查看jquery文档开头。它不是那么简单的事情,也不适合发布一个片段来说明。你将不得不在这里熟悉几个可能的新概念。
http://docs.jquery.com/Main_Page
Here's the direct link to jQuery's ajax documentation.
这是jQuery的ajax文档的直接链接。
http://api.jquery.com/category/ajax/
If you've never done jQuery, its kinda weird, but definitely worth taking the time to get used to.
如果你从来没有做过jQuery,它有点奇怪,但绝对值得花时间去习惯。
#3
1
One side-note. Do you really need to output a BMP file to display it in the HTML?
一个侧面说明。你真的需要输出一个BMP文件来在HTML中显示它吗?
BMPs are quite heavy and uncompressed, if you must store it in that format serer-side, maybe you can also save a JPG "thumbnail" and output that. It will be much faster, whenever you decide to use AJAX or normal postbacks.
BMP非常繁重且未压缩,如果你必须将它存储在那个格式的serer端,也许你也可以保存JPG“缩略图”并输出它。每当您决定使用AJAX或普通回发时,它会快得多。
As everyone else said, AJAX is the best approach because response will be much smaller (just the contents) than returning the full page.
正如其他人所说,AJAX是最好的方法,因为响应将比返回整页更小(只是内容)。
Also for debugging, apart from Fiddler I like to use Firefox with Firebug, it is an excellent web development tool.
另外,对于调试,除了Fiddler我喜欢使用Firefox和Firebug,它是一个优秀的Web开发工具。
#4
0
if you don't want a full post back, yes.
如果你不想要一个完整的帖子,是的。
#5
0
if you want to provide an useful feature on this then you should go Ajax if not then a postback is OK
如果你想提供一个有用的功能,那么你应该去Ajax,如果没有,那么回发是好的
#6
0
You don't have to use Ajax. You can set your page to AutoEventWireUp="false" and handle all events by hand. Circumvent the Page_Load event on the Button click and voila.
您不必使用Ajax。您可以将页面设置为AutoEventWireUp =“false”并手动处理所有事件。绕过Button上的Page_Load事件并点击瞧。