Using ImageButton rather than Windows button

Last post 07-31-2009 9:43 AM by ctheriault. 2 replies.

Sort Posts:

  • Using ImageButton rather than Windows button

    07-31-2009, 8:45 AM
    • Member
      1 point Member
    • cmfuchs
    • Member since 07-31-2009, 12:07 PM
    • Posts 1

     I wanted to change the Submit button to a graphic and below is my failed attempt.   Any help/suggestions would be appreciated.

    Thanks,

    Code that works with Submit button:

    .aspx file:

    <input type="submit" Value="Submit" runat="server" ID="cmdSignUp">

    .aspx.cs file:

    public partial class _Default : System.Web.UI.Page
    {
     protected void Page_Load(object sender, EventArgs e)
     {
      this.cmdSignUp.ServerClick += new System.EventHandler(this.cmdSignUp_ServerClick);
        }

     private void cmdSignUp_ServerClick(object sender, System.EventArgs e)
     {

    My failed guess at using ImageButton:

    .aspx.file:

    <asp:ImageButton ID="cmdSignUp" runat="server" ImageUrl="../../images/submit.gif" OnClick="Page_Load"></asp:ImageButton>

    .aspx.cs:

    public partial class _Default : System.Web.UI.Page
    {
     protected void Page_Load(object sender, ImageClickEventArgs e)
     {
      this.cmdSignUp.ImageClick += new System.EventHandler(this.cmdSignUp_ImageClick);
        }

     private void cmdSignUp_ImageClick(object sender, System.EventArgs e)
     {

  • Re: Using ImageButton rather than Windows button

    07-31-2009, 9:26 AM
    Answer
    • Participant
      1,420 point Participant
    • krunal.shah
    • Member since 04-03-2009, 11:24 AM
    • india
    • Posts 222

    Hi,

    change your aspx code like,

    <asp:ImageButton ID="cmdSignUp" runat="server" ImageUrl="../../images/submit.gif" OnClick="cmdSignUp_ImageClick"></asp:ImageButton>

    and remove ,

    this.cmdSignUp.ImageClick += new System.EventHandler(this.cmdSignUp_ImageClick); from your cs file.

    and also the CLick event arguments should be,

    private void cmdSignUp_ImageClick(object sender, ImageClickEventArgs e)
     {

    }

    Thanks,
    Krunal
    Please Mark as answer if it helps.it will help others to find the solution.
  • Re: Using ImageButton rather than Windows button

    07-31-2009, 9:43 AM
    • Participant
      1,547 point Participant
    • ctheriault
    • Member since 04-10-2009, 12:33 PM
    • Posts 276

    in addtion to krunal.shah suggestion, set a relative path for your image using '~':

    <asp:ImageButton ID="cmdSignUp" runat="server" ImageUrl="~/images/submit.gif" OnClick="cmdSignUp_ImageClick"></asp:ImageButton>

     

     

    ----
    Don't forget to mark this posting as an "Answer" if it is helpful to you
Page 1 of 1 (3 items)