Professional Web Applications Themes

<input type="image"... based custom control - ASP.NET Building Controls

I have created one of these controls but arent getting any call backs. I've got the source from the MSPress book "Developing Microsoft ASP.NET Server Controls and Components" for SimpleButton.cs (off Chapter 9) and modified the "type" attribute to "image" plus added "src" attrinbute. After clicking on the image the page is being called (I can breakpoint on Page_Load) but the event is lost. I was reading MSDN and it mentions about using "System.Web.UI.ImageClickEventHandler" for any custom image based controls, but no more information. I tried changing EventHandler to this (and everything else that must be changed to cope with ...

  1. #1

    Default <input type="image"... based custom control

    I have created one of these controls but arent getting any call backs.

    I've got the source from the MSPress book "Developing Microsoft ASP.NET
    Server Controls and Components" for SimpleButton.cs (off Chapter 9) and
    modified the "type" attribute to "image" plus added "src" attrinbute.

    After clicking on the image the page is being called (I can breakpoint on
    Page_Load) but the event is lost.

    I was reading MSDN and it mentions about using
    "System.Web.UI.ImageClickEventHandler" for any custom image based controls,
    but no more information. I tried changing EventHandler to this (and
    everything else that must be changed to cope with this type) but the event
    is still lost.

    I was wondering if anyone knew what more does one have to do in the control
    to get events to work?


    Thanks in advance,

    Alfred


    Alfred Tascon Guest

  2. #2

    Default Re: <input type="image"... based custom control

    Alfred,

    Is autopostback set to true on the control?
    Post some code and maybe I will be able to help. Kinda tough to tell
    without seeing it.


    DB
    Danny Bloodworth Guest

  3. #3

    Default Re: <input type="image"... based custom control


    "Danny Bloodworth" <dbloodworthinfinitechs.com> wrote in message
    news:91e799a5.0410141026.7c3e1196posting.google.c om...
    > Alfred,
    >
    > Is autopostback set to true on the control?
    > Post some code and maybe I will be able to help. Kinda tough to tell
    > without seeing it.
    >
    >
    > DB
    Taken from an MSPress Book and modified a little:
    // SimpleButton.cs
    // Developing Microsoft ASP.NET Server Controls and Components
    // Copyright 2002, Nikhil Kothari and Vandana Datye
    //

    using System;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace MyWeb.Controls
    {

    // The SimpleButton control participates
    // in postback event handling by implementing
    // the IPostBackEventHandler interface. It
    // exposes a Click event which it raises in the
    // IPostBackEventHandler.RaisePostBackEvent method.

    [
    // The DefaultEventAttribute allows a page
    // developer to attach a handler to the default
    // event by double-clicking on the control.
    DefaultEvent("Click")
    ]
    public class SimpleButton: WebControl, IPostBackEventHandler
    {

    protected override HtmlTextWriterTag TagKey
    {
    get
    {
    return HtmlTextWriterTag.Input;
    }
    }

    [
    Category("Action"),
    Description("Raised when the button is clicked")
    ]
    public event EventHandler Click;

    protected override void AddAttributesToRender(HtmlTextWriter writer)
    {
    base.AddAttributesToRender(writer);
    writer.AddAttribute(HtmlTextWriterAttribute.Name,t his.UniqueID);
    writer.AddAttribute(HtmlTextWriterAttribute.Type," image");
    writer.AddAttribute(HtmlTextWriterAttribute.Value, "");
    writer.AddAttribute(HtmlTextWriterAttribute.Src, "images/or.bmp");
    }

    // Method of IPostBackEventHandler that raises postback events.
    void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
    {
    if (Click != null)
    {
    Click(this, EventArgs.Empty);
    }
    }

    protected override void Render(HtmlTextWriter writer)
    {
    // Ensures that this control is nested in a server form.
    if (Page != null)
    {
    Page.VerifyRenderingInServerForm(this);
    }
    base.Render(writer);
    }
    }
    }

    ******* The aspx page(called default.aspx):
    <% Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="false"
    Inherits="MyWeb.default" %>
    <% Register TagPrefix="cc1" Namespace="MyWeb.Controls" Assembly="MyWeb" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>default</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema"
    content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <cc1:SimpleButton id="SimpleButton1" style="Z-INDEX: 101; LEFT: 32px;
    POSITION: absolute; TOP: 16px"
    runat="server"></cc1:SimpleButton>
    <asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 40px; POSITION:
    absolute; TOP: 48px" runat="server">Nothing Clicked</asp:Label>
    </form>
    </body>
    </HTML>


    ******** The aspx.cs file (called default.aspx.cs):
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;

    namespace MyWeb
    {
    /// <summary>
    /// Summary description for default.
    /// </summary>
    public class default : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Label Label1;
    protected MyWeb.Controls.SimpleButton SimpleButton1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    int i=0;
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.SimpleButton1.Click += new
    System.EventHandler(this.SimpleButton1_Click);
    this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    private void SimpleButton1_Click(object sender, System.EventArgs e)
    {
    Label1.Text = "Clicked";
    }
    }
    }


    *************************
    I have not been able to get the control to raise an event.
    Page_Load is being called after I click on the control, but no event.
    Funny if I change the "type" from "image" back to "submit", events are
    raised again.

    Does anyone know what else has to be done to get "image" types to work?
    How does ImageButton do it?

    Please help !!!!


    Thanks in advance

    Alfred



    Alfred Tascon Guest

  4. #4

    Default Re: <input type="image"... based custom control

    Alfred,

    The only thing I can offer is that when you change the type to image,
    you have to specify that the control should postback where the submit
    button is inherently going to postback. Try adding an attribute to
    the control for autopostback and set the value to True. I am a VB
    guy, and I'm having a bit of trouble getting the C# stuff in the code,
    but it seems that with an image as the base control, you would have to
    tell it to postback.

    HTH,

    Danny
    Danny Bloodworth Guest

Similar Threads

  1. Help please: Exception when with <input type="file"> but not with Textbox
    By Drew Berkemeyer in forum ASP.NET Web Services
    Replies: 1
    Last Post: November 16th, 10:22 AM
  2. problem with reset/clear in <input type="file" >
    By 123nani123 in forum Macromedia Dynamic HTML
    Replies: 1
    Last Post: July 22nd, 07:42 AM
  3. HTML + <input type="File">
    By Bhavin in forum ASP
    Replies: 2
    Last Post: October 22nd, 03:21 AM
  4. <input type="file"> readonly
    By Jarrod in forum ASP
    Replies: 1
    Last Post: October 2nd, 10:48 AM
  5. #25366 [NEW]: form buttons of type "image" dont send "submit" $_POST variable in IE
    By jordanolsommer at imap dot cc in forum PHP Development
    Replies: 0
    Last Post: September 2nd, 07:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139