HtmlInputImage and Postback event

Discussion in 'ASP .Net' started by Alex, Nov 29, 2004.

  1. Alex

    Alex Guest

    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, Nov 29, 2004
    #1
    1. Advertising

  2. Alex

    Vaibhav Guest

    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" <> wrote in message news:%...
    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, Nov 29, 2004
    #2
    1. Advertising

  3. Alex

    Alex Guest

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

    --
    Alex
    "Vaibhav" <> wrote in message news:...
    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" <> wrote in message news:%...
    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, Nov 29, 2004
    #3
  4. Alex

    suni.sunil

    Joined:
    May 5, 2010
    Messages:
    1
    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.
    suni.sunil, May 5, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JP

    HtmlInputImage.ServerClick

    JP, Nov 13, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    1,492
    Jacob Yang [MSFT]
    Nov 14, 2003
  2. Mark Lingen
    Replies:
    5
    Views:
    13,606
  3. Psych971
    Replies:
    5
    Views:
    4,588
    bruce barker
    Dec 17, 2004
  4. =?Utf-8?B?Q2hhZA==?=

    Postback not being set to True on first postback

    =?Utf-8?B?Q2hhZA==?=, Apr 4, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    478
    =?Utf-8?B?Q2hhZA==?=
    Apr 4, 2005
  5. Replies:
    5
    Views:
    1,555
    Virgil Schleich
    Jul 7, 2005
Loading...

Share This Page