Adventures in Development Babak's experiences in software development

26Feb/100

jquery, ajax, and .NET Web Services

Recently, I have been working on a few projects that require an ajax friendly life cycle for an ASP.NET web application. Much of the work I did is based on Rick Strahl's post: http://www.west-wind.com/weblog/posts/896411.aspx.

Working on top of what I learned from this article, I decided to leverage the rich capabilities of .NET's Web UI components as part of my ajax implementation using HTML injection. I used jquery to bind a standard button to make a call to my Web Service method.

The service created and populated a standard GridView object. The service would then render that object and return the HTML that was generated. This HTML, once returned by the service call, would be injected into a DIV tag that served as the container for the results table.

My initial implementation is a naive solution that renders full HTML on the server side and passes that back to the client-side. My ASP.NET page already has a script manager so I added a reference to my web service (simple .asmx in this scenario).

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/Services/MyService.asmx" />
</Services>
</asp:ScriptManager>

My service defines a method Foo:

namespace Client.Project.Services
{
/// <summary>
/// Summary description for ConceptServices
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1, Name = "MyBinding")]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class ConceptServices : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod]
public String Foo()
{
return "<table><tr><td>Hello World!</td></tr></table>";
}
}
}

To make a call to this method via client-side javascript, simple use the fully qualified name for the method:
Client.Project.Services.Foo( successMethod, failureMethod )
Assuming Foo is overloaded to take in parameters, you would pass in those parameters first:

var i = 3
var s = "bar"
Client.Project.Services.Foo( i, s,  successMethod, failureMethod )

18Nov/090

BootBootReboot.com

I have been working on a website to aggregate funny technology related content across the internet. So far, I have been able to integrate pictures, YouTube videos, and some RSS content from fmylife and clientcopia

I have created the site using ASP.NET and SQL Server. I made this decision solely because I use Microsoft's platform every day for my professional work.

BootBootReboot.com

Picture Uploads and Thumbnails

The pictures page (http://www.bootbootreboot.com/pictures) allows visitors to add their own pictures. Upon uploading a picture, a thumbnail is also generate for that picture. The code below shows how to create a thumbnail of an uploaded image.

public System.Drawing.Image CreateThumbnail(System.Drawing.Image original, int width, int height)
{
return original.GetThumbnailImage(width, height, null, new IntPtr());
}

Ajax using jquery + .NET Web Services

Recently, I have also been introducing some new ajax functionality using jquery and .NET web services. This combination has allowed me to easily introduce a "preview" feature for uploading images and YouTube videos.

Content Management

Youtube Videos

The site is being updated to use the Youtube play list as the content manager for the videos page. Comments and ratings will be retrieved for the detail page and visitors to bootbootreboot.com can add their own comments and ratings.