How do I check if a submit IMAGE was clicked via Request.Form?
The following checks if a submit BUTTON was clicked via Request.Form by returning the value of the submit button if clicked:
<form action="Default.aspx" runat="server" method="post" id="newform">
<input type="submit" id="submit" value="Submit!" runat="server" />
</form>
<%
if (Request.Form["submit"] != null) //TRUE
{
Response.Write("Submit button pushed");
}
Response.Write(Request.Form["submit"]); //Returns "Submit!"
%>
The following checks if a submit IMAGE was clicked via Request.Form, but it DOESN’T return any value after the image was clicked:
<form action="Default.aspx" runat="server" method="post" id="newform">
<input type="image" id="subimg" src="solar_image.gif" alt="Can't show image" value="Submit Image!" runat="server"/>
</form>
<%
if (Request.Form["subimg"] != null) //FALSE
{
Response.Write("Image Submit button clicked!");
}
Response.Write(Request.Form["subimg"]); //Doesn't return "Submit Image!"
%>
The above code works for me in IE 9 and Chrome. Only way I can replicate is when using the Firefox as a browser.
This link sheds more light on the issues Firefox 4.0 beta — as well as IE and Opera — do not send name/value for input type=”image”; only .x and .y coordinates are sent.
The following check works in every browser I’ve tested: