Menu

HtmlInputImage causes postback in control

Help
Nathan
2008-10-10
2013-06-03
  • Nathan

    Nathan - 2008-10-10

    Hi, I have a custom control, and one of my child controls that I want is an image button.  If I do a regular input btn:

    System.Web.UI.HtmlControls.HtmlInputButton, then I can run a javascript function directly:

    System.Web.UI.HtmlControls.HtmlInputButton hSaveBtn = new System.Web.UI.HtmlControls.HtmlInputButton ();
    hSaveBtn.ID = "saveBtn";
    hSaveBtn.Name = "saveBtn";
    hSaveBtn.Value = "save";
    hSaveBtn.Attributes.Add ( "onclick", ID + @"InPlace.saveTiny();" );

    And it doesn't do a postback ( it works correctly )

    But interestingly enough if I have an Image button, it causes a postback, which really screws things up. 

    System.Web.UI.HtmlControls.HtmlInputImage hSaveBtn = new System.Web.UI.HtmlControls.HtmlInputImage();
    hSaveBtn.ID = "saveBtn";
    hSaveBtn.Name = "saveBtn";
    hSaveBtn.Src = "~/OMWAImages/Crystal_Clear_action_apply.png";
    hSaveBtn.Attributes.Add ( "onclick", ID + @"InPlace.saveTiny();" );

    Any hints?

     
    • Zan

      Zan - 2008-10-25

      you need to prevent the default action from occurring, you can do this by appending return false to the onclick code

      hSaveBtn.Attributes.Add ( "onclick", ID + @"InPlace.saveTiny(); return false;" );

       

Log in to post a comment.