473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Show image when button is pressed

52
Hi guys,

Just a quick and simple question:

i'm trying to have a loading image displayed when a submit button is pressed.

Basically what I have at this stage is an asp:image with its visibility set to false, and in the onclick function of the button the visibility of the image can be toggled.

This is fine however, the onclick function of the button also needs to load a lot of thing, and the change in image visibility does not get updated until all the stuffs are finished loaded on the server and the page is reloaded; which makes the use of the "loading image" pointless.

Is there a way to make the image update immediately after the button is pressed? There has to be because it's quite common...

Cheers,



Billy
Jan 12 '09 #1
4 13408
Frinavale
9,735 Expert Mod 8TB
Please post the code that displays the image and the code where you call it.

-Frinny
Jan 12 '09 #2
liawcv
33
Just wondering if you were trying to show the hidden loading image by using server-side codes (e.g. C# or VB.NET). And as you said, it doesn't make sense if you do it at the server-side.

In fact, all this should be done at client-side (i.e. by using JavaScript). Let make things simple: Firstly, make the loading image hidden from the view of user. You SHOULDN'T do it by setting its server-side Visible property or the loading image will not be rendered (i.e. sent) to the client-side at all. To allow its visibility to be updated by JavaScript, use CSS style rule (i.e. "display: none") instead.

Secondly, attach a JavaScript statement that shows the loading image on the button's client-side onclick event (i.e. OnClientClick property).

Here are some simple examples of how to show / hide an image by using JavaScript (let Image1 the loading image and Button1 the button):

Expand|Select|Wrap|Line Numbers
  1. // To show
  2. document.getElementById("Image1").style.display = "block";
  3. // To hide
  4. document.getElementById("Image1").style.display = "none";
  5.  
Let back to our case: In order to make it works in ASP.NET, you may have to write codes to (1) hide the loading image by setting its CSS style property (NOT the Visible property) and (2) attach the necessary JavaScript statement to the button's client-side onclick event. All these are to be done on the Page_Load event handler. E.g.

Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(...)
  2. {
  3.    if (!Page.IsPostBack)
  4.    {
  5.       // Hide the loading image initially
  6.       Image1.Style["display"] = "none";
  7.  
  8.       // Attach JavaScript to the button's client-side onclick event
  9.       Button1.OnClientClick = 
  10.          "document.getElementById('" + Image1.ClientID + "').style.display = 'block'";
  11.    }
  12. }
  13.  
That's all. You are not required to re-hide the image after the button is clicked. Changes to the loading image's style property at client-side are not visible to the server. Thus, the image will be hidden every time after reload.

And, it is important to use the Image1.ClientID to retrieve the correct client-side ID of the loading image. Or, the codes will not work if master page is used.

Suggestion
Try AJAX technology if you would like to implement a more complex scenario, e.g. show the loading image while temporary disable the entire page. AJAX makes the job much more simple, and sometime code-less.
Jan 12 '09 #3
200dogz
52
Hi guys,

Thanks for the help.

I was trying to perform it on the server-side, and doing it on the client side solves the problem :).

Cheers,



Billy
Jan 12 '09 #4
bharathreddy
111 100+
thanks I was also searching for the same answer.......:) Great work....


Thanks
Bharath Reddy VasiReddy
Mar 24 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Jack | last post by:
I want to display a table on a page based on whether a button is pressed or not. I'm new at php so I'm sure I'm making a basic mistake. Here's what I am trying. My thought was that $show_summary...
4
by: nath | last post by:
Does anybody know how to make an image a "submit"-button WITHOUT using JavaScript ? means i have three image buttons in my first.jsp. if i press first image it has to go back.jsp when i...
9
by: sergio | last post by:
Hi all, I have created the following script that will show/hide a menu based on checkboxes. It works fine in Opera but not on IE6! Does anybody knows a workaround this problem? Thanks for your...
3
by: Russell | last post by:
I have a web page that i am using an image button as my submit button. The code behind the button works, but when I click enter on the web page, nothing happens. Can anybody tell me how to get my...
6
by: ruca | last post by:
Hi gurus, I have a imagebutton in my WebForm, and I want that when I click (mouse down) on her the imagebutton change image and when I "unclick" (mouse up) change to the original image. Basically...
4
by: Shapper | last post by:
Hello, I have an image button in a web page. The default image is ShowPanel.gif. When the image is clicked I want the panel "myPanel" to become visible and the image button to change to...
3
by: Scott | last post by:
Hello, I am running into a problem with my code and can't seem to figure out the solution. I know it has to do with the pciture box control and unloading the image inthe picture box but I can't...
1
by: Phil_Cam | last post by:
Hello All On a webpage I have a standard paypal image button for purchases. I am trying to set it up so that it only shows up or is endabled when text is entered into a textbox and a button is...
16
by: browntown | last post by:
so I have this application I'm nearly finished with. The only thing the client has requested is the ability to submit the form by pressing "enter". I didn't think this would be a huge pain in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.