views:

52

answers:

2

you must have seen widgets like code which people place inside their HTML and it starts showing a small widget in there, how we can we do it in ASP.net, for example if i want to show some specific data of my site to anywhere some specific code is placed, how can i generate that embeddable code that can start showing my specific block of data to anywhere from any site?

A: 

Here are a few methods used by various people to embed a snippet of content on an external website.

1) An iframe!

iframe's can be a right old pest, but are quite good at displaying a bit of external content. They have been added back into the HTML standards in the HTML 5 draft specification, so you should get futureproof support for them in the future.

<iframe src="http://www.widget-address.com/Widgets/SomeWidget/" title="Some Widget"></iframe>

You can style your iframe (give it a width and height) and all that jazz.

2) External Image

This is largely used by advertising engines. You pop an image on the page and the image is dynamically created to display some advert - each time it appears it is different. This isn't great if you want information to be screen-readable (i.e. accessible).

<img src="http://www.widget-addrees.com/Widgets/SomeWidget.jpg" alt="Some Widget">

3) Server Side API

You could make an API available so people can call a "service" on your site that supplies them with the information for the widget. For example, their ASP.NET code or PHP code (or whatever language) calls http://www.widget-address.com/Widgets/WidgetService/ and it returns some data that they can format and display on their page. This would give you the benefit of inline HTML, which is the most accessible and valid way of displaying the data.

There are lots of other methods, so if you don't fancy one of these, I'm sure more suggestions will flood in - including (be careful...) JavaScript / AJAX.

Sohnee
Thanks, but i dont think it responds to my question, im actually looking for a way where users can put some kind of embeddable code like <html code here> in there pages and those pages start showing some data that i have on my server, its not real widget, it could be any code, like links, or images or pure html..
Ali
A: 

I'm not quite sure I understand the question, so I'm sorry if I'm way off here. But I guess you are using the webforms framework for asp.net? If you are there is something called server controls. Those can be used to create widgets like calenders for example (that is already included in the framework, so no need to build it again).

If you are looking for code block, similar to <?php [[code]] ?> in php (if you have used that), then the answer is <% %>. Those are code blocks in the .net world. If you want to write something out you use Response.Write("string to write"); inside the code block. Or you can use the faster way: <%="string to write"%> that will render the same think (string to write).

If you are using the webforms framework you can also take advantage of the built in server controls in the framework. You can read more about the framework here or simply google asp.net webforms.

Mattias Jakobsson
I understand server controls, and response.write or response.write file, suppose i have a site in asp.net and i have some data on a page in that site, which i want to show on another site which is in PHP, or even pure html, how would i do that? So basically what i want to do is that i should have some specific embeddable code like <%JS code that will get the data based on a url written here%> and where ever on any site in ineternet i place that code and it should start showing the data based on the url i gave in that code block.
Ali
Then I can't see why you can't use a iframe?
Mattias Jakobsson