Event fired twice with custom control

Discussion in 'ASP .Net' started by Daniel, Mar 4, 2007.

  1. Daniel

    Daniel Guest

    I've created a custom control including some Literal ( constructed
    with html markup) and an ImageButton firing event ( add a vote ).

    public event VoteCommandEventHandler VoteCommand;

    protected override void CreateChildControls()
    {
    LiteralControl ltrBeforeVote = new
    LiteralControl(buildMarkupBeforeVoteButton());
    this.Controls.Add(ltrBeforeVote );

    btnVote = new ImageButton();
    btnVote.ImageUrl =
    this.Page.ClientScript.GetWebResourceUrl(typeof(UnPourTous.MyWebControl.Article),
    "UnPourTous.Resources.plus.jpg");
    btnVote.Style["border-width"] = "0px";
    btnVote.Style["position"] = "absolute";
    btnVote.Style["right"] = "5px";
    btnVote.Style["top"] = "2px";
    btnVote.Attributes["onClick"] =
    Page.ClientScript.GetPostBackEventReference(this, "vote");
    this.Controls.Add(btnVote);

    LiteralControl ltrAfterVote = new
    LiteralControl(buildMarkupAfterVoteButton());
    this.Controls.Add(ltrAfterVote );
    }

    public virtual void RaisePostBackEvent(string eventArgument)
    {
    switch (eventArgument)
    {
    case "vote":
    if (VoteCommand != null)
    VoteCommand(this, new
    VoteCommandEventArgs(ArticleID));
    break;
    case "commentaire":
    if (CommentCommand != null)
    CommentCommand(this, new
    CommentCommandEventArgs(ArticleID));
    break;
    }
    }

    This custom control is instanciated many times and each instance added
    to a panel control's list.
    Instanciation occurs in the page OnLoad event
    The panel appears once in the main aspx page.
    In the container page an eventhandler is registered to listen to the
    VoteCommand fired by the PostBackEvent.
    Everytime the button is clicked, a vote is normaly added to a
    database.
    But my problem is that the event is fired twice. Two votes are added
    to the database.

    It seems that an other event is firing after the button click.

    Thanks in advance...!
    Daniel, Mar 4, 2007
    #1
    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. Rick Lubanovic

    onbeforeunload event is fired twice

    Rick Lubanovic, Oct 30, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    811
    Rick Lubanovic
    Oct 30, 2003
  2. Anup
    Replies:
    2
    Views:
    902
    Anup Daware
    Aug 8, 2006
  3. Roberto Kohler
    Replies:
    0
    Views:
    501
    Roberto Kohler
    Nov 6, 2007
  4. SammyBar
    Replies:
    1
    Views:
    584
    Erjan Gavalji
    Jul 21, 2009
  5. SammyBar

    Custom event from a custom web control is fired twice

    SammyBar, Jul 14, 2009, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    915
    Erjan Gavalji
    Jul 21, 2009
Loading...

Share This Page