How to avoid down loading an image

  • Thread starter Thread starter Cal Who
  • Start date Start date
C

Cal Who

I want an aspx page to first call a sub that uses confirm() to ask the user
if he want an image displayed.

Something like I show below.

I could have check() simply use window.location to go to the next page if
the user refuses and to return if he says to display the image.

However, even if he refuses the image has already been down loaded which is
should not happen if the user says "no"..

How would you do this?



Thanks





<asp:Content runat="server" ID="Content4" ContentPlaceHolderID="BottomCPH">

<<script type="text/javascript">check()</script>

<img style='border: 0px; width...

</asp:Content>
 
This is more of a JavaScript question than an ASP .NET one but, after
confirming that the user wants the image displayed, you can dynamically
create a client-side image object and then load it into an existing image
tag:

var img = New Image();
img.src = "path";
var theImage = document.getElementById("existingImgTagName");
theImage.src = img.src;

-Scott
 
I haven't been able to use your suggestion because I can't get past some
problems.

I save a cookie with either of the ways shown below and then after a

window.location = "Home/Home.aspx";

takes me to a new window I check with

If Request.Cookies("HideSomeParts").Value Then

Do you see anything wrong with that?

Thanks





// 1 yr from now

var expdate = new Date ();

expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000*365));

document.cookie = 'HideSomeParts=True; expires='+expdate.toGMTString();

OR

Public Sub SaveCookie(ByVal CookieName As String, ByVal CookieValue As
String)

Dim current As HttpContext = HttpContext.Current

Dim tmpCookie As HttpCookie = New HttpCookie(CookieName)

tmpCookie.Value = CookieValue

tmpCookie.Expires = DateTime.Now.AddYears(1)

current.Response.Cookies.Add(tmpCookie)

End Sub









(e-mail address removed)...
 
Here is a better descripyion of what happens:
Using JavaScript I set the cookie to true and then do a window.location to a
new aspx window.

In that page I click a checkbox on the master and in the CheckedChanged sub
I save the cookie as False but when the code gets to the Page_PreRender sub
I check it and the value is True.

Why isn't it False there?


Thanks

This is how I check it
If Request.Cookies("HideSomeParts").Value Then

or
If Request.Cookies("HideSomeParts").Value.Contains("True") Then
 
Here is a better descripyion of what happens:
Using JavaScript I set the cookie to true and then do a
window.location to a new aspx window.

In that page I click a checkbox on the master and in the
CheckedChanged sub I save the cookie as False but when the code gets
to the Page_PreRender sub I check it and the value is True.

Why isn't it False there?

Here is how it works

1. user hits page
2. User says no
3. Cookie created
4. Look for cookie (not sent yet)
5. Image shown
6. Cookie and page information sent to browser

AND

7. Refresh page
8. Cookie found
9. Image not shown

Whether the checkbox is set or not is not the issue.

This is really an architectural problem more than anything. Here is how
I would set up the code.

In page load
1. Check for cookie
2. If not exist, send user to form (do you want images)
3. If exists, check if user wants images
4. If wants images show images

In button click
1. Check checkbox
2. If yes, show image and set cookie to true
3. If not, don't show and set cookie to false

This covers both the a) here and now and b) future when the user
returns.

Peace and Grace,


--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Gregory A. Beamer said:
Here is how it works

1. user hits page
2. User says no
3. Cookie created
4. Look for cookie (not sent yet)
5. Image shown
6. Cookie and page information sent to browser

AND

7. Refresh page
8. Cookie found
9. Image not shown

Whether the checkbox is set or not is not the issue.

This is really an architectural problem more than anything. Here is how
I would set up the code.

In page load
1. Check for cookie
2. If not exist, send user to form (do you want images)
3. If exists, check if user wants images
4. If wants images show images

In button click
1. Check checkbox
2. If yes, show image and set cookie to true
3. If not, don't show and set cookie to false

This covers both the a) here and now and b) future when the user
returns.

Peace and Grace,
Thanks, I'll see how that works.
 
Back
Top