JQuery to get file from a webservice

Note: I have moved to blog at my own domain, so kindly visit this post over there for recent updates or comments. http://www.imranbalouch.com/blog/index.php/2011/07/jquery-to-get-file-from-a-webservice/

Recently we were working on a project, which was ASP.NET 3.0 based and used jquery to get and set data. Our design was to have Presentation layer at separate place and business layer at separate place, so we introduced webservices in it.

We had a use case in which user has to download file, either PDF or ZIP file. In traditional server side code we use to put the byte array of file in Response and user get a download option but in jquery we got stuck as byte array wasn’t getting handled by jquery.

The soultion that we implemented was that we created a server side static method with return type string in our ASP.NET and marked it as a WebMethod.

public static string DownloadFile(Int64[] requestId)

if input parameter array has one value, system returns PDF otherwise ZIP file.
Our server side gets data from the web service and writes the file in a folder and return the file virtual path like http://localhost/myapp/tempfolder/myfile.zip to the calling jquery method.

jquery method than uses that url by calling window.open method and user gets that file downloaded.

I feel like that its not a better way of doing it but still don’t have any other.
I will be glad to have a better suggestion from anyone.

All is Well!


Postback behavior of dropdown in firefox

Note: I have moved to blog at my own domain, so kindly visit this post over there for recent updates or comments. http://www.imranbalouch.com/blog/index.php/2011/03/postback-behavior-of-dropdown-in-firefox/

I am not sure that either it is behavior of firefox or not but that was a strange thing that happened to me during a development.

I have a web application in ASP.NET and C#. On a page I have a drop down list, which works fine in IE. However in firefox if I click on the dropdown, it get expanded, now if i type some charcter, relevant value get selected, now if i click out side the dropdown anywhere on my page, dropdown collpased, new value is shown as selected but no post back occurs even auto post back is set to true.

I even put a client side function to call on change of value, but that also didn’t get called.

I feel like that it is behavior of firefox, caz it appears that firefox postbacks data after dropdown looses focus. on 1st click the focus is at the dropdown and on 2nd click dropdown looses focus. But the wiered thing is that in dropdown new value is being displayed to the user.

But on the other hand if we see it is a nice behavior of firefox, caz on dropdown list if autopoastback is set to true than in IE, if u move focus to dropdown and type A, first value starting with A is selected and page is post backed where as firefox waits for lossing focus so that if selected value is not your desired one than u can reach desired value and avoid extra post backs.

A way out that I found to avoid it in case of mouse usage is to capture the onclick event of dropdown in javascript and hold a value that the dropdown is opened now and capture onclick event of page and see if previous click was on dropdown and new click is not on dropdown than using dopostback, make a post back for the dropdown. I know currently its a wiered solution but right now i figured out only this way to handle it.

All is Well…