how to change cached picture from javascript - asp.net

I have a asp image control. ImageUrl="images/avator.jpg". I'm changing this picture on the server and then setting imageUrl same as previous url on the client. but image don't changed. When i click refresh button, image changed.
How to change cached image won't changing url?

You can add random number as a paramentr to avoid caching.
<img src="http://someurl.com/avatar.png?version=0.01.135";
The best way is to add number of application build version. So every time you change something in aplpication everything will load again.

Related

HTML Change button state permanenty

I am completely new to web development. The question I have is rather simple (I guess), but after multiple hours of using google and experimenting I am still without any solution. The problem I have is probably not how to do it, but which keywords to use while searching.
I want to create a simple website. (For testing I use Caddy Server). For my website I use a simple index.html file. On my website I want to have 9 buttons, which will be disabled once clicked. After refreshing the page, every client should also see the changes, so the button-state has to be stored somewhere on the server.
Then there will be another button, which sets the web page to its initial state (all buttons enabled). The purpose of this web page is that 2 persons can click buttons successivley until only one button is left enabled (the web page reloads itself every second on every client). This will be used to select a certain map from a map-pool of 9 maps.
My main problem is, to store the button states, so after refreshing the page the buttons should be still disabled if they were clicked. All clients should see the buttons as diabled once they refresh their pages. Do I have to implement a database for this or store the button states in xml or json? Do I need javascript, jquery, php or ajax for this? I do not want to make it very complicated, so if I need for example a database for this, I will probably just give up.
What I'm asking for: Any point in the right direction on how to implement a simple button that keeps its state after reloading the page would be much appreciated. I found a solution for this using JQuery, but it does not work for me (button does not preserve state after refreshing See here).
Thank you so much for any help!
Your server will need a data store (database) to save the values desired for each button.
Client Side
Set disabled attribute on all relevant buttons in your HTML. On (client-side) page load, fetch the value(s) from your server (database) and depending on what the returned value(s) are, .clearAttribute("disabled") on all buttons accordingly.
Server Side
Have your server set the disabled attribute on the HTML <button> elements based on values in your database prior to serving the HTML to your client(s).

Load image dynamically into asp:Image control

I'm using an asp:FileUpload control to give the user the chance to look for an image on the hard drive, once the user has chosen the image, after a button is pressed, I want to display the image in an asp:Image control.
I've been trying to get the full path of the file but I can't get it, I'm using Path.GetFullPath(FileUpload.FileName) but I'm getting a totally different path, not the path to the image that the user selected.
I was reading that I need to set the src attribute of the asp:Image control to be an aspx page which is going to return the image, and then I have to write the bytes from the image to the response but I'm not sure how to do this (I'm a newbie in web development), I don't know what should I put in my event, in the code behind, or what code should I place on the aspx page that will return the image, neither how to call the aspx page with the image from the event handler.
Can anyone show me a good example on how to achieve this please?
The issue here is the file being uploaded resides on the client computer where the asp:image control is looking for an image on the server computer.
What you should be doing is on the form submit/button click save the file into the application folder then reference that file with your asp:image control.
You can use the project mentioned below to preview the image before uploading. Working sample is also attached.
http://www.dotnetspider.com/resources/40858-Preview-Image-before-uploading-using.aspx
This uses AjaxControlToolKit's AsyncFileUploadControl and HTTPHandler to upload the image.

First deployment, ASP.net image buttons not showing when page is first loaded

I finally got my site to work on my server, and it is now visible at http://www.mhn.co but when you click on any of the categories on the top it loads a professional's profile, but the image buttons I'm using like tabs on the profile content don't load, and just display "Submit Query" until clicked on, then the images load. This is my first asp.net site that I've deployed so I'm pretty unfamiliar with how this should work. The server is running asp.net 2.0, 3.0, and 3.5, and my site is using 2.0
Are you assigning image on load ? Cause the src is null or empty at first. And on the click
you probably added the image on postback or something.
before click :
src = "";
after click
src = "./css/img/content_tab_profile_rollover.jpg"
Try adding image on the load
It's not a problem with the server. It's a problem with the markup or control you're using. Because if you look at the image URL it's trying to use when it first loads it's "http://www.mhn.co/profile.aspx?name=Mounir". But then when you click it works because it points to "http://www.mhn.co/css/img/content_tab_profile_rollover.jpg".
Without seeing your code/markup we can't really do much more. But that is where I'd look

Dynamic web user control problem when browser's back button is clicked

I have an .aspx page in which I dynamically add web controls to a panel.
The problem is when I hit the browser's back buton, it's displayed a version of the page that no longer exists on the server-side, because the controls are dynamically added.
Let's say my aspx dynamically adds Control1. From there, I click a button that loads Control2.
At this moment, if I press the browser's back button, it will display the page with Control1, but Control1 no longer exists on the server-side, so if I interact with it, some erractic behaviour will occur. Any ideas on this?
Thank you very much.
Have you tried setting the client side to not cache pages - stick this in your page load:
Response.Cache.SetCacheability(HttpCacheing.NoCache)
(Think the syntax might be slightly off, but you should be able to figure it out)
Have you tried with removing temporary files and restarting browser. Your page might be cached in browser.

How do I - in ASP.NET save the info from a page when a user leaves the page?

In our CMS, we have a place in which we enable users to play around with their site hierarchy - move pages around, add and remove pages, etc.
We use drag & drop to implement moving pages around.
Each move has to saved in th DB, and exported to many HTML files. If we do that in every move, it will slow down the users. Therefore we thought that it's preferable to let the users play around as much as they want, saving each change to the DB, but only when they leave the page - to export their changes to the HTML files.
We thought of making the user click a "publish" button when they're ready to commit their changes, but we're afraid users won't remember to do that, because from their stand point once they've moved a page to a new place - the action is done. Another problem with the button is that it's inconsistent with the behavior of the other parts of the site (for example, when a user moves a text inside a page, the changes are saved automatically, as there is only 1 HTML file to update)
So how can we automatically save user changes on leaving the page?
You should warn the user when he leaves the page with javascript.
From http://www.siafoo.net/article/67:
Modern browsers have an event called window.beforeunload that is fired right when any event occurs that would cause the page to unload. This includes clicking on a link, submitting a form, or closing the tab or window.
Visit this page for a sample the works in most browsers:
http://www.webreference.com/dhtml/diner/beforeunload/bunload4.html
I think it's bad practice to save the page without asking the user first, thats not how normal web pages work.
Sample:
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
function unloadMess(){
mess = "Wait! You haven't finished."
return mess;
}
function setBunload(on){
window.onbeforeunload = (on) ? unloadMess : null;
}
setBunload(true);
//-->
</SCRIPT>
The easiest way I can think of is to store the page info each time the user moves items around using Ajax (e.g. with an UpdatePanel, onUpdated event, let it fire some script that updates the users page config.
Alternatively - .Net's WebParts implementation does this automatically without intervention by the programmer (unless you want to change the storage engine, it uses a local mdb in by default.
Use a "Publish" checkbox/button and when the user interacts with the page in a way that causes them to navigate away ask them if they want to publish if that box is NOT checked/button not clicked. Be aware that there are actions (closing the browser, accessing their favorites menu, etc.) that you will probably not want or not be able to prompt the user.
I would force them to click a button such as publish. That is a 'training' issue.
Automatically saving changes when they leave could have other ramifications. For example if a user opens up a record and plays around with it and has no intention of changing it, they close it, like a word document, excel, etc. . . I would have your site mimic that model.
You also have to remember that the web is a disconnected environment and is not required all web applications run like a windows application.
If the user doesn't click the publish/save button then there changes are not saved and that is up to them to remember to do.

Resources