redirect to an image - c#

Why can't I redirect page to a image for example:
Response.Redirect("http://www.domain.com/images/image.gif");
This doesn't show me the image. Also placing conten type image/gif doesn't show the image.

Works for me. I created an "images" folder and added the following to the Page_Load method of my Default.aspx page:
Response.Redirect("~/images/scenery.jpg");

try relative path, not a complete url
meaning Response.Redirect("images/image.gif");

Related

ASP.NET Redirection

I'm currently redirecting a page using
Response.Redirect("URL");
this works great, however it changes the url too. For example:
http://localhost/index.aspx
Redirected to: test.aspx will change the url to:
http://localhost/test.aspx
Is it possbile to redirect the content without changing the URL?... so the Url will be:
http://localhost/test.aspx
BUT the content would of been redirected to
test.aspx
Thank you.
Try to use Server.Transfer(URL); to avoid changing the url.
More info here.
And also check the differences at this post and this one.
Make sure that this solution meets your needs.
Use Server.Transfer
This will show the content of default.aspx page, but it will not change the url
Server.Transfer("Default.aspx");

Set an image in UI

Im using .net c# MVC3 Model. I need to show a gif called loading when I click save on the page. I used <img src="sourcepath" alt="loading" style="display:none"/> and trying to display it whenever user clicks save button using jquery. I have stored the image temporarily in views folder. Unfortunately, i could not see image on the screen. I can see its division with a small red cross cancel button.
Pls Help
If you're seeing the broken image icon, it means your src "sourcepath" is wrong. You would normally put static content in the Content folder of your site, and access it using /Content/imagename.jpg or /Content/Images/imagename.jpg or similar.
Try to use the search, here you can find an solution the show an spinner when doing ajax requests:
How to show loading spinner in jQuery?

Set background image for a master page that use in sub directories

I have a master page in my web site root.I have a folder named Images in root that Contains a background image for my master page.When I use this master page for my root web pages every thing is OK. But when I use this master page in web pages placed in sub directories because it can not find back ground image,ground image does not show.I don't want to use MapPath and get absolute path of image.
How I can show background image every where my master page use.
thanks
Refer to your images with prefixing slash in your CSS style:
body
{
background-image:url('/images/background.jpg');
}
In master page page load event set the source attribute of image in the given format
protected void Page_Load(object sender, EventArgs e)
{
backgroungimageId.src=Page.ResolveUrl("~/Images/xyz.jpg");
}

Load HTML file using MonoDroid

I want to load an local html file as part of my Help Screen. I have placed the file "test.html" in my Assets folder.
Here is my code:
WebView web_view;
web_view=FindViewbyId<WebView>(Resource.Id.webview);
web_view.Settings.JavaScriptEnabled=true;
web_view.LoadUrl("file://test.html");
I am getting a "Web page not available" error.
Thanks in advance. TB
web_view.LoadUrl("file:///android_asset/test.html);
Use this line instead of that
web_view.LoadUrl("file:///test.html);
Use this line instead of that because use "file:///" not "file://" please change and after Run.

ResolveURL not resolving in a user control

I'm trying to use ResolveUrl() to set some paths in the code behind of a custom ASP.NET user control. The user control contains a navigation menu. I'm loading it on a page that's loading a master page.
When I call ResolveUrl("~") in my user control it returns "~" instead of the root of the site. When I call it in a page I get the root path as expected. I've stepped through with the debugger and confirmed, ResolveUrl("~") returns "~" in my user control code behind.
Is there some other way I should be calling the function in my user control code behind to get the root path of the site?
look at System.Web.VirtualPathUtility.ToAbsolute.
wonde's comment above led me to the answer --
I was attempting to use ResolveUrl before the control's page load fired. Therefore there was no context page for the function yet.
I moved my code into the page load function and now it's resolving as expected.
Thanks for the nudge in the right direction.
Take a look at this MSDN example. http://msdn.microsoft.com/en-us/library/system.web.ui.control.resolveurl.aspx. and Rick Strahl's Web Log http://www.west-wind.com/Weblog/posts/154812.aspx
I suppose if it works on the page but not the control i guess you could try
this.Page.ResolveUrl("~");

Categories