Displaying dynamically created image on my ASP.NET WebForm - asp.net

On my Form Load event I am creating a bitmap using System.Drawing classes, and I want to display this image on my WebForm. How can I do that?
Thanks!

You can't create this bitmap directly in your webform. You will need to implement custom HttpHandler that will render this image separately.
Serving Dynamic Content with HTTP Handlers
HTTP Handlers for Images in ASP.NET
Use Custom HTTP Handlers in Your ASP.NET Applications

Instead of creating the image in the code behind for your page, what you should do is create a URL for the image that somehow describes or defines the image's content (perhaps along with session state or a cookie if you need to), and attach that URL to a regular <img> (or <asp:Image>) tag.
Then, when the browser requests that URL, your code determines the parameters from the query string or cookies or whatever, generates and sends the response, and returns it with the correct MIME type. That's usually best done from a Generic HttpHandler (*.ashx).

Related

redirect data from a servlet to flex page?

I have String datatypes in a servlet/jsp page, I have a submit button on that page, through which I want to redirect the page to flex application such that the application would print those values.
You can append your data in the url after user click 'submit':
http://dest_flex.html?name=StackOverflow&age=20...
dest_flex.html is the host page of the .swf.
in dest_flex.html, you can use javascript get the url paramters.
in the swf, you can get the paramters from javascript in as using ExternalInterface.
then you can dispaly the data in your flex application.

Microsoft Access - Web Browser ActiveX Control - Only show one DIV

Ok, I have an ActiveX web browser control on an Access form.
I am loading a url into this control using the following code:
Dim webMain As Object
Set webMain = Me.WebBrowser2.Object
webMain.Navigate "http://stackoverflow.com"
However, this page has multiple DIV's and I only want to show one.
Thanks
John
From your comment
I am only interested in one div in my form, as the other two are
menu's which they don't need to use or see. They just need to fill in
the form located within the main div and hit submit.
Well why bother with displaying HTML to them at all. Just collect the data on your Access form with Unbounded controls and POST the HTTP form yourself using MSXML2.ServerXMLHTTP or WinHttp.WinHttpRequest.5.1
For a sample see How can I send an HTTP POST request to a server from Excel using VBA?

Write binary data as a response in an ASP.NET MVC web control

I am trying to get a control (not a controller -- a subclass of System.Web.UI.WebControls.WebControl), that can be used that I wrote for ASP.NET to work in an ASP.NET MVC environment. Normally, the control does the normal thing, and that works fine
Sometimes it needs to respond by clearing the response, writing an image to the response stream and changing the content type. When you do this, you get an exception "OutputStream is not available when a custom TextWriter is used".
If I were a page or controller, I see how I can create custom responses with binary data, but I can't see how to do this from inside a control's render functions.
To simplify it -- imagine I want to make a web control that renders to:
<img src="pageThatControlIsOn?controlImage">
And I know how to look at incoming requests and recognize query strings that should be routed to the control. Now the control is supposed to respond with a generated image (content-type: image/png -- and the encoded image). In ASP.NET, we:
Response.Clear();
Response.OutputStream.Write(thePngData); // this throws in MVC
// set the content type, etc
Response.End();
How am I supposed to do that in an ASP.NET MVC control?
You could create a custom ActionResult. Here is a link to a blog post for creating a custom ImageResult class that subclasses ActionResult. http://blog.maartenballiauw.be/post/2008/05/13/ASPNET-MVC-custom-ActionResult.aspx

Output dynamic image into the source of a asp.net control

I found out how to generate an image in code-behind based on some input from a webform, great. now i want to put that image back onto the form after the postback. All the samples i found use the Response to send the image back out to the browser with a stream.
Is there anyway to specify that the image generated in the code behind, be the source of a image control (or placeholder or whatever)?
If there is a way of doing this is there way of doing it without saving the image to the disk?
thanks
The web browser has to be able to retrieve the image somehow. If you don't want to save it, then it will require sending it with a Response stream.
You can create an HTTP Handler (ashx) and based on query string parameters generate and return an image. This would allow you to specify the image objects "ImageUrl" property as "~/MyImageHandler.ashx?param1=value1"
The http://imageresizing.net library can dynamically process images, as well as generate them. Could you provide more detail about what you are trying to do?

Substitution Control at the User Control Level?

I am trying to create some cached user controls. Basically Header and Footer are static.
Except the footer has one link that reads in the URL of the page and puts it into the javascript for sending a link to a friend. So I need that link to be dynamic.
I set up a substitution control and had the static method return the dynamic link.
Go to run and find that substitution controls are not supported at the user control level.
Is there any work around to this? Is there another control like substitution that works on the User Controls that I am not aware of?
I would forget about server side caching in this instance and rely on the simplicity of client side caching.
Your Javascript code could be client side cached just as easily as HTML, either by linking to an external javascript file and adding the necessary headers/expiries, or by embedding the script within the page itself and ensuring the page itself is cached.
Another possible method is by making an Ajax call on the page load to fetch the generated footer complete with correct link. This may take time on the first page load, but subsequent ajax requests would be cached on the client, thus seeing no penalty to future requests.

Resources