Home » Category » DotNet

DotNet: HtmlInputImage and Postback event

204| Sun, 01 Jun 2008 10:05:00 GMT| alex| Comments (2)
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

Keywords & Tags: htmlinputimage, postback, event, dotnet, .net

URL: http://dotnet.itags.org/dotnet-tech/313842/
 
«« Prev - Next »» 2 helpful answers below.
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

"Alex" <alex...nospam.net> wrote in message news:%23AvyUZk1EHA.3376...TK2MSFTNGP12.phx.gbl...
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

vaibhav | Sun, 01 Jun 2008 10:06:00 GMT |

Thanks for the help. Adding return false; to my onclick even solved this issue.
Alex
"Vaibhav" <consultvaibhav...yahoo.com> wrote in message news:OAXtXzk1EHA.3452...TK2MSFTNGP14.phx.gbl...
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

"Alex" <alex...nospam.net> wrote in message news:%23AvyUZk1EHA.3376...TK2MSFTNGP12.phx.gbl...
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

alex | Sun, 01 Jun 2008 10:07:00 GMT |

DotNet Hot Answers

DotNet New questions

DotNet Related Categories