SilverStr
Posts: 28
Joined: 2013-03-31
|
Hey guys,
I am making some pretty good progress on the Addin. Way to go on a simply framework that is easy to use.
With that said, I have a weird condition that I can't seem to figure out.
Because I am intercepting so many different elements in the SupportedEvents, I understand that OnClick() could get fired lots of times. However, what I am seeing is that when I dump the srcElement of the click it is showing up several times. In other words, clicking on an element seems to show the same srcElement several times.
Here is the process how I am seeing this:
- User clicks on an element
- I catch the OnClick() and pop up a dialog asking some info about it
- If the user hits cancel, I want to permit them to select another element, and as such set e.Cancel = True;
At this point, my dialog pops up again BEFORE another click. Does so 7 or 8 times. Which shows the same srcElement, which is definitely not what I am expecting.
I thought maybe somehow its nesting. So if the user clicks on an anchor that is in a div... well I would be willing to accept that the A is in one entry, then the div etc. But srcElement seems to show the tagName as the A in all entries.
Am I making sense? Is there any way to mark an OnClick() event as finished when I set Cancel so any further OnClicks() from that event are supressed so the dialog isn't poppe dup again, and again, and again. (One for every call into OnClick()) |
|
Sergey Grischenko
Add-in Express team
Posts: 7235
Joined: 2004-07-05
|
Hi Dana,
I will try to find a solution for you and will post a sample code. |
|
SilverStr
Posts: 28
Joined: 2013-03-31
|
That would be great Sergey. Its got me pretty stuck.
Looking forward to the code snippet! |
|
Sergey Grischenko
Add-in Express team
Posts: 7235
Joined: 2004-07-05
|
Hi Dana,
Please try the code below:
private bool eventsBlocked = false;
private void adxiehtmlDocEvents1_OnClick(object sender, object eventObject, ADXCancelEventArgs e)
{
if (eventsBlocked) return;
mshtml.IHTMLEventObj2 eventObj = eventObject as mshtml.IHTMLEventObj2;
if (eventObj != null && eventObj.srcElement != null)
{
if (!String.IsNullOrEmpty(eventObj.srcElement.tagName))
{
if (eventObj.srcElement.tagName.ToLower().Equals("a"))
{
e.ReturnDefaultValue = false;
e.Cancel = true;
this.eventsBlocked = true;
MessageBox.Show(this, "Anchor clicked.");
}
}
}
}
private void adxiehtmlDocEvents1_OnMouseUp(object sender, object eventObject)
{
this.eventsBlocked = false;
}
|
|
SilverStr
Posts: 28
Joined: 2013-03-31
|
That worked perfectly Sergey. Thanks! |
|