Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Event fired twice with custom control

Reply
Thread Tools

Event fired twice with custom control

 
 
Daniel
Guest
Posts: n/a
 
      03-04-2007
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(Un PourTous.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...!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom event from a custom web control is fired twice SammyBar ASP .Net Web Controls 1 07-21-2009 07:16 PM
Custom event from a custom web control is fired twice SammyBar ASP .Net 1 07-21-2009 07:16 PM
Embedded <divs> with events: How to prevent the parent div's eventfrom being fired when the embedded div's event is fired? Num GG Javascript 2 11-17-2008 08:56 PM
click event is fired twice on an enhanced Button Control Roberto Kohler ASP .Net 0 11-06-2007 10:22 PM
onbeforeunload event is fired twice Rick Lubanovic ASP .Net 0 10-30-2003 08:55 PM



Advertisments
 



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