HtmlInputImage and Postback event

A

Alex

In my Asp.net application, I have come across a situation where I cannot prevent a postback using the HtmlInputImage control. If I use the HtmlInputButton, the post back is not automatic, however with the HtmlInputImage, it appears to be.

Add this to your aspx test app and set a breakpoint in your Page_Load.
<input type="button" id="TheButton" value="GO"/>
<input type="image" id="TheImage"/>

When you click on the "TheButton" - no postback occurs. When you click on "TheImage" - a postback occurs. Can someone help me stop the postback for the HtmlInputImage?

Thanks,

Alex
 
V

Vaibhav

Hi Alex

U r right the image click is posting the page to the server. It seems some browser setting is causing the page to post on image click.

I did a workaround by putting onclick="return false;" in the input image control and it no longer submits the page to the server.

<input type="image" id="TheImage" onclick="return false;" />

HTH

In my Asp.net application, I have come across a situation where I cannot prevent a postback using the HtmlInputImage control. If I use the HtmlInputButton, the post back is not automatic, however with the HtmlInputImage, it appears to be.

Add this to your aspx test app and set a breakpoint in your Page_Load.
<input type="button" id="TheButton" value="GO"/>
<input type="image" id="TheImage"/>

When you click on the "TheButton" - no postback occurs. When you click on "TheImage" - a postback occurs. Can someone help me stop the postback for the HtmlInputImage?

Thanks,

Alex
 
A

Alex

Thanks for the help. Adding return false; to my onclick even solved this issue.

--
Alex
Hi Alex

U r right the image click is posting the page to the server. It seems some browser setting is causing the page to post on image click.

I did a workaround by putting onclick="return false;" in the input image control and it no longer submits the page to the server.

<input type="image" id="TheImage" onclick="return false;" />

HTH

In my Asp.net application, I have come across a situation where I cannot prevent a postback using the HtmlInputImage control. If I use the HtmlInputButton, the post back is not automatic, however with the HtmlInputImage, it appears to be.

Add this to your aspx test app and set a breakpoint in your Page_Load.
<input type="button" id="TheButton" value="GO"/>
<input type="image" id="TheImage"/>

When you click on the "TheButton" - no postback occurs. When you click on "TheImage" - a postback occurs. Can someone help me stop the postback for the HtmlInputImage?

Thanks,

Alex
 
Joined
May 5, 2010
Messages
1
Reaction score
0
Hi,
You can also try an another method, if you have a Javascript function on the onclick() event.
Below is a template control which shows an image inside gridview. Onclick event of this control is assigned to a javascript, which reads the entire row and set corresponding values to text boxes. Which also set background image of the gridview row to an image.
If you are facing such a situation you can use the mouseup event for execute javascript and set onclick event to false.

<asp:TemplateField ShowHeader ="false" >
<ItemTemplate>
<%-- <input type ="button" runat ="server" id="imgSelect"
style="border-style: none; width: 14; height: 15;"
onclick ="javascript:setAllowanceFromGridView(this);"
value='<%# ((GridViewRow) Container).RowIndex %>' />--%>
<input type="image" runat="server" id="imgSelect" src="~/App_Themes/SkinFile/Images/play_button.png"
title="Select Allowance" value='<%# ((GridViewRow) Container).RowIndex %>' style="border-style: none;
width: 14; height: 15;"
onmouseup ="javascript:setAllowanceFromGridView(this);"
onclick ="javascript:return false;" />
</ItemTemplate>
</asp:TemplateField>

Thank You.
Regards,
SKB.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top