473,396 Members | 1,712 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,396 software developers and data experts.

HTML input type=image in ASP.NET 1.1 causing current page to reload

jon
Hi

This might be an easy one to answer but I have a web form in an ASP.NET
1.1 application with a hand-rolled HTML image button as follows which
opens a help guide in a new window:

<input type= "image " id= " imgHelp "
onclick="javascript:void(window.open('<%
Response.Write(ConfigurationSettings.AppSettings["HelpURL"]); %>')) ">

The problem that I have is that when the image button is clicked, the
current page re-fires a Load event even though the link launches a new
window and navigates to an external page.

How do I stop the Load event on the user's current page being re-fired?
I've deliberately not used a ImageButton control as the post back would
cause a re-load but even by using a HTML element it seems a postback
is still occurring. Annoying...

Or is there another way of launching a new window from an image button
without causing a page reload?

Jon

May 10 '06 #1
2 6588
jon
As is usually the case, just realised what the problem is straight
after posting. The form element has runat=server so all input controls
cause a postback so I changed the image button (input type=image)
element to a plain img element and attached an onclick javascript
handler and a cursor: hand; style to simulate an image button.

Updated code:

< img style= "cursor:hand;" id="imgHelp"
onclick="javascript:void(window.open('<%
Response.Write(ConfigurationSettings.AppSettings["HelpURL"]); %>'))"
src="images/help.gif">

:)

May 10 '06 #2
Hi,

jo*@jongianni.com wrote:
As is usually the case, just realised what the problem is straight
after posting. The form element has runat=server so all input controls
cause a postback so I changed the image button (input type=image)
element to a plain img element and attached an onclick javascript
handler and a cursor: hand; style to simulate an image button.


Many things are incorrect in your post.

- The fact that the form has runat=server is not the cause for your
problem. In fact, even without runat=server, the input type=image causes
a postback, it's just what it's made for (don't forget that these
elements were defined in a time when JavaScript didn't exist). You had
two ways to cause a postback: either click on a "submit" button, or
click on an image button, which is exactly what you did. Runat=server
simply makes the form available ("visible") to the server side code.

- Second, Images don't have a onclick event handler, at least not in the
standard HTML definition. To make an image "button", you use

<a href="#" onclick="..."><img ...></a>

Replace "..." with the appropriate code. Don't forget that your
application is loaded on all kind of clients, so using standards is
always a good idea.

- Using the "javascript:" pseudo-protocol is only useful when you
execute JavaScript code in the URL bar of the browser. In all other
circumstances, it is not needed, and can even cause problems. So you
onclick code should be

onclick="window.open('<%Response.Write(Configurati onSettings.AppSettings["HelpURL"]);%>');return
false;"

I added return false to specify that the HREF part of the link must not
be executed.

- Embedding ASP.NET code in your HTML code is a bad idea. It's the old
way of doing things. You don't want this for many reasons. Instead, you
can use an ASP Hyperlink, for example, and specify the onclick in the
code behind.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
May 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mark | last post by:
Hi, I create a button in the form in the asp page like is: <input type="image" src="button.gif" name="detail" border=0 value="100234"> How can I get this value from another page? I try sdetail...
3
by: Csaba Gabor | last post by:
When I click on the image form element <INPUT type=image name=point src="map.png"> point.x and point.y values get submitted to the server specifying where on the image I have clicked. Is there...
6
by: Moist | last post by:
Hi, I have an embedded HTML object as follows (ignore the code tag): <code> <object id="page" data="table.html" type="text/html" .... > </code> I look for the Javascript code (placed in...
1
by: champ.supernova | last post by:
Hi, I have a form which has a few different submit links, all of type image. This is critcal to the operation of the form, as it relies on the image co-ords being passed to another page, the...
3
by: jackiepatti | last post by:
QUESTION: I have a web page containing a form that contains an image instead of a submit button, e.g. <form name='myform' action='get' method='otherpage.asp'> <input type='image'...
8
by: John | last post by:
Hi Pasrt of HTML - <div class='button'><input type='image' src='/images/check1.jpg'></input></div> Part of CSS - ..button {background-image: url(/images/check1.jpg); background-repeat:
0
shane3341436
by: shane3341436 | last post by:
I used input type=image in my page.So that when user clicks on this field the page is submitted. The input-image field is working quite well in mozilla. But when same page is run in IE the form is...
10
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario -------------...
1
by: Arpit Nagar | last post by:
Hi... I am creating a dummy project for collage. Here I had choosen my project as Jewelleryshoping. Now the scenerio is like that thier are jewellry item which I had display in table format with...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.