tags:

views:

26

answers:

1

hi,

In my asp.net website I need to return data obtained from DB by adding html tags to it from a server side method,just like a webmethod returns jsonified data. I am having trouble understanding if a webmethod can serve the purpose(i.e., htmlifying the data).If not how do I acheive it?

Could someone please help.

Thanks.

A: 

You could build an ASPX page to hit the DB and craft the result into exactly the HTML you want. You could then call that URL from the webpage, using the Ajax mechanism of your choice, and put the response contents into the desired part of the page. Admitedly, it looks a little odd, calling "foo.aspx" as an ajax call - but I believe it will work.

Caveat: I did something like this on a previous project, but it was a couple years ago, using a very early version of .net (1.1 or 2.0). So I apologize if there's nuances I've left out (viewstate-related hiccups, for example). However, hopefully this will give you a starting point.

mikemanne
thanks a lot.Is there any library available to convert the data obtained from DB into html or I'll have to code it myself?Could you give me an example please?
kranthi
At abstract level, the entire premise of ASP.NET is the ability to take data (often from a DB) and return it back to the user/browser in HTML format - so I'm not 100% sure I understand what you're asking here. At the most basic level, the .aspx file contains/defines the HTML layout. The code-behind (.aspx.cs file) contains code to access the DB. ASP.NET controls placed within the .aspx file are the "linkup", allowing the code-behind to put the database data into the HTML. In particular, DataGrid controls and Repeater controls might be useful.
mikemanne