473,320 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Event fired twice with custom control

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...!

Mar 4 '07 #1
0 1302

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Peter Row | last post by:
Hi, I have created a user control consisting of a textbox and a separate vertical scroll bar. The textbox is filled with data. However there could be lots of data so I only fill the textbox...
7
by: | last post by:
Hello to all I'm handling the Validating event for one text box. If something is wrong in user input I show a warning message. The problem is that if I add to method the message is displayed...
7
by: sanjana | last post by:
hi i wanna detect if a anything is connected to the usb port I am using system.management class for tht purpose this is my code class usbdetect { public static void Main() {
6
by: Steve Caliendo | last post by:
Hi, I'm creating 5 ImageButton controls in the panel control, and I have a unique ID specified for each one. When I click on any one of them, the Page_Load executes (Of course), but how do I...
4
by: Seraph | last post by:
Again, I'm rather new here, so if I fail to follow any etiquette, please forgive me and let me know what I've done wrong, but I think this might interest quite a few people. One of my colleaques...
9
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the...
2
by: Michal Valent | last post by:
I would like to fire some custom server control event before Page_Load event like this (from the trace of an aspx page) : Trace Information Category Message From First(s) From Last(s) aspx.page...
6
by: tshad | last post by:
I was looking at a page that showed how to set up a custom event and it seems to work ok. But I am not sure how I would use it. How would I subscribe to it. There is actual action (such as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.