Fremus.co.za

Demistifying Life and Web Development

Archive for the 'Web Technologies' Category

Dealing with Circular References in EF4/JSON

I like the many-to-many mapping EF4 provides you simply because it allows such great navigation between entities and its easy to shape the query from one side to other and vice verse. The only issue is that it causes issues with JSON serialization, because the serializer does not know how to handle circular references, it can only serialize one way. Initially I dealt with this issue by creating “view classes” but it seemed rather tedious and pointless, so instead I started using the enumerable Select() method. It provides a very easy way to construct “anonymous objects”. So in my controller I would have a JSON Result and I would do something like this:

Json(courses.Courses.Select(t => new { CourseTitle = t.CourseTitle, CourseCode = t.CourseCode, CourseId = t.Id }));

Pretty damn neat, considering that Courses is a EF4 entity and I dont have to go and change or adapt it to play nicely with the JSON serializer.

  • Share/Bookmark
Tags: ,
posted by fr3dr1k in C#,Web Development and have No Comments

Product Navigation Design

As I mentioned in my previous blogpost I am busy working on a website at the moment and a part of the website display dynamic product-related content. I believe that the product navigation is not perfect yet and I think it might be a good idea to take a look at some examples and draw a few conclusions from it. The first example I looked at this morning was Hi Fi Corporation (I was looking at some LCD tv’s) and immediately I started looking at the way the product navigation was done, and here are some of my thoughts:

Products are divided into categories and each category is displayed in two areas, the horizontal menu at the top and a vertical-collapsible menu to the right. Each category links to its own individual page, e.g. prods/audio for Audio products. When you click through to a category page the category bar remains to the left, with another “product filter” bar that appears below it.

On the category page for audio, here, there is a product comparison box and a paging component. Notice that the pages aren’t individual pages but javascripty/ajaxy items. Each product however has its own dedicated permalink. Isn’t it equally important to link to pages? Or is that not that important due to the nature of the data?

If you go to another website, Take 2 (my favourite online retailer for DVD’s and books), you will notice that if you click through to electronics (which is a category much like the Hi Fi Corporation example) you get to a page with sub categories to the left, which when clicked on (e.g. Mp3 Players) produces a paged result page. The difference from the Hi Fi Corporation example is that the pages are not ajaxy and you could probably access an individual page with a link – whereas the Hi Fi Corporation example you couldn’t. I’m not saying its a bad thing, just stating the difference. How would you design a product pager? Make it URL accessible? If you take a look at this Amazon.com page you will see that the paging is ajaxy. The Amazon.com page I just linked to is also bound by category, software architecture, as was the Take 2 and Hi Fi Corporation example. Would it be wrong to surmise that categories are permalinks and the products/items on them are page-able and that the individual pages are not permalinks? I can understand why a page within a category would not make sense as a permalink – simply because the data might change and move around. If 20 new books on software architecture were added today that would affect the pages. You could also argue that a page could give you the top 10 new items which might make sense in a MVC architecture where you could apply action filters.

What would the ideal product navigation design be? Well the ideal product navigation design would take the functional aspects into consideration and produce an effective solution.

  • Share/Bookmark
posted by fr3dr1k in Web Design and have No Comments

A Quick Look at some website design / functionality

I have been working on a new website recently and its far from perfect – in fact I see it being refactored several times before I think it will reach an optimum phase or place. That being said business people don’t buy-in or the see the value in refactoring, so its something only the developer is aware or should be aware of. I digress.

Parts of the design I have been working on seems to have been using scrollable areas a lot and personally I see that as a fatal design flaw for two major reasons:

  • You are forcing design onto the natural flow of information on a web page. Surely the design should work with the flow and nature of a website and not against it. Content is the most important asset on your website and should ideally have a natural flow to it. Personally if you are using too many scrollable areas, you should re-look your design.
  • Not many websites use scrollable areas. Its ok to be different, not indifferent.

In case you are wondering what I mean by scrollable areas, it refers to applying the height property to an area and setting the overflow: auto. The effect is that you have a scrollable area. I cannot find many sites that use this technique actually.

  • Share/Bookmark
posted by fr3dr1k in Web Design and have No Comments

WCF, ASP.NET Webforms, ASP.NET MVC and jQuery

I haven’t written a technical article in a while but I thought I would write one that discusses AJAX calls with jQuery. Before I get into it I would like to reiterate some of my personal development objectives of late:

  1. Don’t do ANY UI manipulation in any of my server side API’s. The sole purpose of any API within the applications I build is to deal with business layer logic and the data related to it. Ideally speaking I would want my API to return structured data which is easily transformed into a format for the client application using the API (e.g. JSON). I have had experiences within another development team in the recent past where the API returned HTML with the data and to say that this is a mess is understating the obvious – if you think about it quickly then you can understand the impact of one style or layout change will have on this approach. It also blurs your application in terms of its concerns and makes testing a problem. So ideally I dont want any UI logic in any of my API’s.
  2. The second objective I have is that all my UI for web applications must be handled with client-side scripts. Client side includes both static HTML, CSS and JavaScript, and in this instance I specifically refer to JavaScript and the handling of my API’s data using JSON, for which I use jQuery. The REST (:D) of this article is dedicated to the AJAX options available in an ASP.NET application.

Dealing with AJAX in an ASP.NET Application

Developing ASP.NET applications gives you two “frameworks” or “architectures” to work with:

  1. ASP.NET Webforms
  2. ASP.NET MVC

Notice that each architecture or framework uses the ASP.NET runtime which in turn runs on the .NET framework, and part of the .NET framework is the Common Language Runtime (CLR). People often think ASP.NET automatically refers to webforms. The difference between the architectures lies both in how it was designed and who it was designed for. Webforms was designed for Windows Forms developers working within the Visual Studio drag-and-drop environment and aimed to provide an abstraction of Windows Forms for the web. With webforms you could simply drag and drop controls onto a design surface and assign properties to the controls. The problem with webforms was that it required state management and to deal with the state management viewstate was created. Basically state management refers to a controls ability to retain its “value state” across postbacks. So if I created a simple label and set its text to “hello world” viewstate is used to retain that text value throughout the life of the rendered page. Webforms also introduced the concept of the Page Life Cycle, which exposed certain events at certain points of the page’s rendering process. The problem with viewstate is that the viewstate is inserted into your HTML pages which causes the page to bloat – so there is no clean markup. Viewstate totally goes against the grain of how the web works – being stateless.

ASP.NET MVC addresses some of the issues associated with webforms by using a mature and well known architectural pattern – Model-View-Controller, as used in Ruby-On-Rails. ASP.NET MVC does not use the page lifecycle for a start and it embraces the web’s statelessness instead of fighting it. The result is that you have no ViewState and this means that there is no HTML bloat and you also have complete control over your HTML.

There are a couple of ways to consume AJAX requests in ASP.NET but they fall into two categories:

  1. SOAP
  2. REST

In my previous development role I worked with guys that used SOAP to do AJAX requests and although this approach was good enough it was specifically aimed at ASMX web services which meant adding web references to your project. Needless to say adding these reference is a pain in the ass, because if a new method was added to a service you had to first update your reference before you could see the method. REST, however, addresses this issue by allowing you to make calls to URL’s, and not by adding any references. It also means that if a new method is created its available immediately. The remainder of this article is about consuming REST-like services in an ASP.NET application.

With my latest development effort I started out by using Page Methods in an ASP.NET Webform application. Why ASP.NET webforms you may ask? Well I wanted to focus on the business value and I just started out with Webforms without concerning myself too much with the technical side of things. Page methods implement a REST-like architecture and simply requires that you add a WebMethod attribute in your code-behind’s CS file like this:

    [WebMethod]
    public static Dictionary> GetLastSixMonthReport()

You could then access the web method through jQuery like this (notice the Default.aspx/GetImportsLastSixMonths):

    $.ajax({
        type: "POST",
        url: "Default.aspx/GetImportsLastSixMonths",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            var dict = msg.d;
            var html = '';
            $("#importsData").empty();
            html += dict;
            $("#importsData").append(html);
        }
    });

The main issue I have with this approach was that if I wanted to create a new web project I had to re-create the web methods – which is not ideal. So if I wanted to move this project over to a new MVC app I would have to recreate the methods. Based on this I decided to create a separate WCF project that could host all my methods and deliver them in a REST-JSON way. To get WCF to deliver JSON in a REST fashion you need to do two important things:

  • Configure it
  • Add the appropriate Interface attributes

Configuring a WCF service for JSON requires that you add an endpoint address to the service itself like this:


You also need to add an endPointBehavior like this:

				
					
				
			

In your service behaviours you need to set httpGetEnabled to true as well. I added this in my service class:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

In service contract I added the WebInvoke attribute to each method, like this:

    [OperationContract]
    [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
    ProductCollectionView[] GetProductCollectionViews();

Once I set this up I could access the JSON-enabled endpoint: http://localhost/LRB2CServiceLayer_v1/LRB2c.svc/ajaxEndpoint/GetProductCollectionViews and I would see the JSON. Notice that the JSON comes with a MethodNameResult as opposed to the “d” from the page methods. Consuming it uses a similar approach to the jQuery for page methods, except that you use a GET (which is a little dodgy):

    $.ajax({
        type: "GET",
        url: "http://localhost/LRB2CServiceLayer_v1/LRB2c.svc/ajaxEndpoint/GetProductCollectionViews",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            var dict = msg["GetProductCollectionViewsResult"];
            var html = '';
            $("#importsData").empty();
            html += dict;
            $("#importsData").append(html);
        }
    });

I decided to convert the WCF service to a class library (DLL) instead because I had all kinds of issues with XSS because I ran the WCF service as a separate web application. The idea was that a WCF service was easily shared between web apps. I basically combined the class library with a MVC web app instead. A class library can just as easily be shared among multiple projects or web sites. The JSON that MVC returns is different to WCF and Webforms – it just returns the object, no indexer/key such as “d”. Getting MVC to return JSON is pretty straight forward:

        [HttpPost]
        public JsonResult GetGetProductCollectionViews()
        {
        }

Of the three methods/technologies I described I like the ASP.NET MVC approach because:

  • Its RESTful
  • The JSON result only contains the object(s)
  • Share/Bookmark
posted by fr3dr1k in AJAX,ASP.NET,ASP.NET MVC,Web Development,Web Technologies and have No Comments

Calling all Young African (Web) Designers

Africhic and Quirk eMarketing have devised a way to give Web Design hopefuls a shot at a year’s paid internship at Africa’s largest full service digital agency and the chance to shine by designing the winning new skin for the online shop, Africhic.com. You’ll find the full brief here.

Africhic was the winner of the Africa Fashion Awards Retailer of the Year 2010, a worthy honour as Africhic.com does far more for aspirant young African designers than flog their fashion on the Internet. Rather it gives South African fashion designers and increasingly, designers from the rest of the continent a platform to showcase their work, philosophy and passion for African design to a global market.
Quirk eMarketing and Africhic are offering students in the creative fields an opportunity to showcase their own take on African creativity by redesigning the look and feel of the Africhic website. Fashion legend, Robyn Cooke will be on the panel of judges. Robyn is a long time player in the local fashion scene and is respected as a stylist, as the editor of Styleguide Cape Town and as Fashion Editor for O Magazine.

Submissions close 30 September 2010 and the winner will be announced shortly thereafter and will see their artwork come to life on the new Africhic website, as well as R5000 in online credit for their shopping pleasure on Africhic.com.The winner will also be able to pursue a career in the digital creative arts, kick started by a coveted internship at Quirk eMarketing. 

Quirk has a passion for creativity in Africa and is promoting this competition with Africhic by offering the winner a Web design internship. The Quirk internship programme is a year’s paid apprenticeship under the watch of some of the best minds in marketing and technology in South Africa. Quirk is a leading digital agency with branches in London, Cape Town and Johannesburg, and Quirk’s interns have the unrivalled opportunity to glean the latest knowledge in the new media and digital fields, and to contribute their minds and talents to the development and implementation of exciting digital campaigns for clients such as DStv, Distell, Sun International and SA Tourism.

The Ethical Fashion Movement
Fashionistas of the world are currently spending in the region of US$1trilion every year on clothes, while ethical fashion is a growing trend with 27 percent of British consumers surveyed saying they are willing to pay a premium for fashion, footwear and accessories produced in a socially and environmentally sustainable way.

Clothing and textiles represent seven percent of the world’s exports, and in light of the current demand for sustainable sourcing, innovation in skills, recycling, and organic fabrics, all practices that African designers have been promoting for years, there is a bright opportunity for African fashion businesses to successfully compete in the international market for fashion.

“Quirk instantly took a liking to Africhic because of the evident pride the website takes in African innovation, a passion Quirk shares,” says Emma Carpenter, Creative Director at Quirk eMarketing.

“Africhic’s advocacy on behalf of local, aspirant talent and promotion of ethical fashion are values Quirk can stand by. The skin design competition we are supporting should work to further strengthen the image of South Africa as a source of creative talent, including digital talent, and to make people aware of the wealth of creativity Africa has to offer,” says Carpenter.

To Enter:
Submissions should reflect high fashion with a global appeal, while remaining true to the spirit of Africa, both urban and ethnic. The winning submission will add a new and fresh layer of meaning to outdated and over-used notions of African fashion and culture. Think Shack chic, modern versions of Africa and let the creative juices flow. The deliverables on this project are in the brief.

About Africhic:
Africhic.com is an online luxury fashion retailer for African designer fashion. It boasts a virtual catwalk on which local designers Suzaan Heyns, Undacova, Stiaan Louw, Lunar, Michelle Ludek, Kenyan designer, Lalesso and others showcase their talent, giving fashionistas all over the world the chance to buy unique designer fashion that is 100 percent African and 100 percent ethically sourced. Our vision and goal is to increase our stable of designers to 50 by the end 2010 and to advance the local industry and African fashion more generally through increased exposure and access to these products.

What the Quirk?
Quirk eMarketing is strategy-led full service digital agency with branches in London, Cape Town and Johannesburg. Quirk was born in March 1999 with the sole purpose of providing innovative digital services to the global business community. Known for being smart and creative, we have a passion for digital and are constantly updating our skills and services in the belief that enough is never enough. Using our unique knowledge and abilities, we apply the fusion of marketing and technology for the benefit of your business. Today, Quirk is an ever-growing agency with a loyal client base that includes brands like Capitec Bank, DStv, MWEB, Distell, Sun International, The Financial Times and Warner Bros.

  • Share/Bookmark
posted by fr3dr1k in Web Design and have Comment (1)

Ajax in the .NET environment…

Ajax is not new, its not revolutionary, but it has changed the way I view web development. Javascript no longer comes as a might-have, instead it comes as a critical part of any website application. These days I use JavaScript as the UI scripting tool of choice, and I try to steer away from doing to much UI lifting in my server side code. jQuery makes dealing with UI quite pleasant.

I have also, in the last year and a half or so, been coding without MS Ajax. I have let go of things like the UpdatePanel and the Script Manager and have instead come to do direct Ajax calls to .ashx, default.aspx and web services. It feels that when you follow this approach that you have much tighter control over the quality of the UI. So what are your options for making Ajax calls in a .NET environment? I would like to think that there are a few options that stand out:

  • Direct page ajax calls – you can use jQuery’s ajax function to call .ashx and .aspx pages. I have recently started using the [WebMethod] attribute in my .aspx files to make calls, and what I like about it is that you can tell the page to output JSON, which automatically serializes the method’s return type. I have also used ashx files to do ajax calls and this worked well
  • SOAP-based web services – an approach I learned last year was to use a javascript soap parser to parse soap-based web services. These were mainly .asmx services. You can configure .asmx services to return JSON as well
  • WCF-services can be configured for SOAP or JSON but also use a REST-like approach

What other options are there for .NET developers when making Ajax calls?

  • Share/Bookmark
Tags: ,
posted by fr3dr1k in AJAX,C#,Web Technologies and have No Comments

Windows Live Writer

Microsoft come in for a lot of flack from the OSS world and the Mac users think they are better than everyone else when it comes to software. But I was surprised again today by how good Windows Live Writer integrates with my WordPress Blog, to such an extent that I will in all probability not use the WordPress WYSIWYG editor in the browser, for which I have a reason or two. Firstly, the WYSIWYG editor runs in the browser and I find quite a few things annoying:

  • When I create a blockquote it adds a lot of spacing around it for some reason
  • When I update a post or page the scrollbar will go to the top, instead of staying where I last edited
  • The working area is relatively small

Compare this to what Windows Live Writer offers:

  • Seemless integration with the blog engine. It was so easy to setup and it detects everything, from your theme to all your posts
  • When you write a post you can edit it directly on a themed page, or you can do it in source view. You can also preview it perfectly
  • You have access to ctrl + b, ctrl + i. A total lie on my part. I was using the HTML view here and not the Visual View! WordPress does support ctrl + b and crtrl + i.
  • You dont lose scroll position
  • Publishing is easy and seemless

So in my view Microsoft have really done well with this free piece of software, it just works, and it works better than some Firefox plugins I have used as well.

  • Share/Bookmark
posted by fr3dr1k in Software,Wordpress and have No Comments

2 Twitter Clients I use

After following a link from Kevin Dente to a twitter client called Mixero and installing it I thought I would just list my 2 favourite Twitter clients, why I like them and what I dont like. First of all to those who do not see or understand the value of Twitter, its NOT Facebook and it does not attempt to be Facebook. Twitter is a micro-blogging platform that has taken the world by storm and clearly if you do not “get it” you may never. I have had friends asking me “What is Twitter?”, “Is it like Facebook”, and I’m like you don’t get it so leave it. I use Twitter for one primary reason, fresh content. I get updates from top Microsoft guys in a quicker way than say through an RSS feed, and Twitter seems nicer than RSS feeds to me. So that is why I keep going back to Twitter, because knowledge is good, and if you know about things its always good.

In essence Twitter uses a 140 character mini-blog post from a user, me or you, about anything you think is important, and sometimes what some people say is important. Scott Gu is easier to follow through Twitter, as is people like Scott Hanselman and Phil Haack. The social media’lites also use Twitter extensively. So when you post a Tweet (thats the term used) you have a choice of ways to do it, each with their drawbacks:

  • Twitter: Go straight to the source, to the fountain, to the mothership. You will need a browser for this though (Internet Explorer/Chrome/Firefox) and although it does the job, once you close that browser window the connection to Twitter dies and any new content coming through wont be seen. Your Twitter page itself also refreshes content, but you need to click on a UI (user interface) element to get it to show the new tweets. So this is not my favourite way of connecting to Twitter. I do like the once-in-a-while changes to the main twitter login page though. :P
  • Tweetdeck: I have been using Tweetdeck for quite some time now and I like it primarily because it allows me to update Facebook statuses and Twitter at the same time. I also like it because it notifies me when new Tweets are made. I dislike it because the UI that appears when a new Tweet comes in can get in the way sometimes, even though it has a close buttons
  • Seesmic Look: I like it because it has been written using WPF and it looks slick and pretty. It does not display notifications of new Tweets though, which I wish it had
  • Share/Bookmark
Tags:
posted by fr3dr1k in Twitter,Web 2.0 and have No Comments

Interesting code with HtmlAgilityPack

Yesterday I was busy with HTML to PDF conversion and for this I used the HTML Agility Pack. Everything worked great, except it seemed IE and FF/Chrome render different HTML. So today I took some fairly straightforward HTML and pushed it through HTMLAgility:






	
	




New Website Under Construction

And if I use this code to loop through the childnodes:

            HtmlDocument doc = new HtmlDocument();
            string s;
            StringBuilder builder = new StringBuilder();
            using (StreamReader reader = new StreamReader(@"C:\Documents and Settings\user\Desktop\fremus.net\index.htm"))
            {
                while ((s = reader.ReadLine()) != null)
                {
                    builder.AppendLine(s);
                }
            }
            doc.LoadHtml(builder.ToString());
            Console.WriteLine(doc.DocumentNode.ChildNodes.Count);
            foreach (HtmlNode node in doc.DocumentNode.ChildNodes)
            {
                Console.WriteLine(node.Name);
                foreach (HtmlNode childNode in node.ChildNodes)
                {
                    Console.WriteLine("\t\t" + childNode.Name);
                    foreach (HtmlNode grandChildNode in childNode.ChildNodes)
                    {
                        Console.WriteLine("\t\t\t" + grandChildNode.Name);
                    }
                }
            }

I get the following result in my command line window:
cmdline

As you can see from the output the html node has a text node. The head node has a text node, and it has 9 childnodes including 5 #text nodes. The body node has a text node as well, and it has 7 childnodes, four being #text and the other three being div. So what is this #text node? If you read this article on the W3C site you will see that it states:

A common error in DOM processing is to expect an element node to contain text.

However, the text of an element node is stored in a text node.

On the same page it then gives an example using a title tag. If you do a Google on “html #text node“, you will see that the second result points to an article and if you read the bit on the nodes it seems that each #text node is a child. The #text nodes that appear in the body node seem to point to the text spaces after each div or each element inside the body node. If I change my code slightly:

                    Console.WriteLine("\t\t" + childNode.Name);
                    foreach (HtmlNode grandChildNode in childNode.ChildNodes)
                    {
                        Console.WriteLine("\t\t\t" + grandChildNode.Name);
                        Console.WriteLine("\t\t\t\t" + grandChildNode.HasChildNodes);
                    }

It tells me that the divs have child elements, but the #text nodes do not. Thus it seems for each ‘empty space’ inside a node there exists a #text node. If I amend the HTML from earlier like this:





	
	







Then the footer div will have two text nodes, and the paragraph node will have a textnode. My issues yesterday had to do with the way IE rendered the HTML and that when I used HTMLAgility to parse it, the node counts weren’t the same. From the sample HTML I have given so far that difference is negligble, but I found that if I went to a site like this one and I saved the HTML from IE and Chrome into separate HTML files and I ran my code with that HTML, I got different node counts. Here are two screenshots that illustrate this:
chromeie

The first screen is the html from the page saved from chrome and the second one is from ie. Notice the extra text nodes.

  • Share/Bookmark
posted by fr3dr1k in Browsers,C# and have No Comments

Getting POST values with an ASHX file

Today I had this scenario where I wanted to post items from multiple HTML input elements to a generic handler (.ashx) file without using the action attribute of the form. Specifying the action meant that that you are navigated away from the page where the action is happening, which means re-creating UI logic. How did I achieve this? By using an XMLHttpRequest and using a POST method. GET places everything inside a querystring, which is ok, but I just wondered what would happen if the content was too long for the querystring. I guess the same can be said for POST, but it just seems POST uses a different way to transfer the data. So lets say you had this JavaScript:

    getXMLHTTPPostObject: function(url, elementName, parameters) {
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else {
            alert("Your browser does not support XMLHTTP!");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4) {
                document.getElementById(elementName).innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("POST", url, true);
        xmlhttp.send(parameters);
    }

I use this function to create an XMLHttpRequest object by passing it:

  • the URL for the AJAX call
  • an elementName to put the result of request in
  • A parameter list

I then have a function like this:

    addPost: function() {
        objXMLHTTP.getXMLHTTPPostObject("url to handler", "categoryTemp", "postTitle=" + document.getElementById("txtPostTitle").value + "&blogpost=" + document.getElementById("txtBlogPost").value);
    }

The function gets the values of two HTML input elements and passes it as parameters. The parameters are then used in the POST HTTPMethod. My next challenge was to get the data in the generic handler (.ashx) so that I can process it. I also wanted to return the data from the ASHX file to see that its processed successfully. So in my handler I created this code:

        context.Response.ContentType = "text/plain";
        System.IO.Stream body = context.Request.InputStream;
        System.Text.Encoding encoding = context.Request.ContentEncoding;
        System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
        //if (context.Request.ContentType != null)
        //{
        //    context.Response.Write("Client data content type " + context.Request.ContentType);
        //}
        string s = reader.ReadToEnd();
        string[] content = s.Split('&');
        for (int i = 0; i < content.Length; i++)
        {
            string[] fields = content[i].Split('=');
            context.Response.Write("
" + fields[0] + "
"); context.Response.Write("
" + fields[1] + "
"); } //context.Response.Write(s); body.Close(); reader.Close();

I first create a class of type Stream that is instantiated through the Response.InputStream property, after which I set the content encoding for the response object. I then create a StreamReader instance and call its ReadToEnd method. After this I do some string manipulation and return the text back to the XMLHttpRequest object, which then writes the content to an HTML Element.

  • Share/Bookmark
posted by fr3dr1k in AJAX,C#,Web Development,Web Technologies and have Comment (1)
Get Adobe Flash playerPlugin by wpburn.com wordpress themes