Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to Add OnClick Event to AREA TAG? (Read 3465 times)
Pravin
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 7
Joined: Apr 12th, 2007
How to Add OnClick Event to AREA TAG?
Apr 12th, 2007 at 4:59am
Print Post  
Hi

Can anybody please show an example code, how to add the onlick event in the Area tag

somthing like this...

<AREA onClick="javascript:alert('Hello!');" >

Say I have several boxes. I want to add the onlick event to each of generated Area tag for the boxes.

Can you show the piece of code or idea, how to do that.

Thanks,
Pravin
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to Add OnClick Event to AREA TAG?
Reply #1 - Apr 12th, 2007 at 6:03am
Print Post  
Hi,

You could assign the script to the Hyperlink property:

node.HyperLink = "javascript:alert('Hello!');"; // C# syntax

Or handle the CreatingArea event and add the onClick attribute, e.g. here is a modification of the WebApp example:

Code
Select All
private string createMap()
{
	FlowChart fc = (FlowChart)this.Session["fcx"];
	if (fc != null)
	{
		HtmlBuilder hb = new HtmlBuilder(fc);
		hb.CreatingArea += new AreaEventHandler(hb_CreatingArea);
		return hb.CreateImageMap("map1");
	}

	return "";
}

private void hb_CreatingArea(object sender, AreaEventArgs e)
{
	if (e.Item.ZIndex == 0)
	{
		string script = "onClick=\"alert('Hello!');\"";
		e.AreaTag = e.AreaTag.Insert(e.AreaTag.Length - 1, script);
	}
}
 



Note that this event is raised only for boxes whose Hyperlink is set.

I hope that helps,
Stoyan

ps. You might also check the beta version of our ASP.NET diagramming control:
https://www.mindfusion.org/_beta/NetDiagram.zip
  
Back to top
 
IP Logged
 
Pravin
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 7
Joined: Apr 12th, 2007
Re: How to Add OnClick Event to AREA TAG?
Reply #2 - Apr 13th, 2007 at 4:12am
Print Post  
Hi,

I tried in both the ways (by assigning box.hyperlink and by adding onclick attribute) using alert function. It works fine.

But when I have javascript function inside the script in aspx page like this

<script type="text/javascript">
function sify()
{
alert('Hello Pravin')
}
</script>

in the code behind file
i assigned hyperlink property of the box

Box.HyperLink = "javascript:sify();"

In the browser, when i click on the box, it does not call the javascript function in the script.


But the same thing, when i tried by adding the onclick attribute to the AREA tag, I was able to call the javascript function.

Why was I not able to call the javascript function by assigning box.Hyperlink?

And one more thing... I need the idea how to do this... Let us say there are several boxes on the flowchart. when the user clicks on the box, I need to get the text of the clicked box and call a javascript function by passing box.text as the argument.

Please help with this.

Thanks,
Pravin
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to Add OnClick Event to AREA TAG?
Reply #3 - Apr 13th, 2007 at 6:04am
Print Post  
Hi,

The Item argument of the CreatingArea event gives you access to the Box. On the server side you can get the Box.Text and insert its value as parameter in the Javascript code.

The "javascript:..." hyperlink might not work if the HtmlBuilder.Target is set to open a new page.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint