how to return data in HTML pattern from asp.net method/webmethod?
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 pu开发者_C百科rpose(i.e., htmlifying the data).If not how do I acheive it?
Could someone please help.
Thanks.
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.
精彩评论