Javascript function not called at first click

Hi, I need a little help.



I have a GoLabeledLink with a MidLabel.

I need that only the MidLabel is clickable. To do so I override the GetPartInfo method as explained and check if the selected object is a GoText.

Here the code:



public override GoPartInfo GetPartInfo(GoView view, IGoPartInfoRenderer renderer)

{

foreach (GoObject o in view.Selection)

{

GoPartInfo info = renderer.CreatePartInfo();

info.ID = this.relationID;

if (o is GoText)

info.SingleClick=“ShowRelation()”;



return info;



}

return renderer.CreatePartInfo();



}



When I click for the first time on the MidLabel nothing happens… the javascript function is called only from second click.



Do I miss something?



Thanks for your help!

Because the object isn’t selected the first time this code gets called, and you are only creating the SingleClick if the object is in the Selection.

You should only reference "this" and subparts in the GetPartInfo.
Look at the GetPartInfo samples in Flowgrammer Chartnode or DataSetDemo PersonNode or Processor FlowLink.

Maybe I’ve not explained well the situation, its my fault…



I’m using the GoDiagram version for ASP.Net 1.1 (yes… my site is very old… ;) )

I’m overriding the GetPartInfo method on a class derived from GoLabeledLink, not on a node.

this means that I don’t have a “Kind” property.



I need (if possible) that when the user click the MidLabel that contains a GoText object (but not the link), a javascript function is called.



Hope that now is more clear…



thanks a lot for your patience!

“Kind” is a property of ChartNode. I probably shouldn’t pointed you at that.

StateCharter allows single click action on a GoLabeledLink.
But you want the label, and not the link itself, to call SingleClick. Is that right?

Ok, you’re right! ;)



I actually have a simple GoLabeledLink whith a MidLabel.

I need that only the MidLabel is clickable and call a javascript function.



The link should not be clickable.



Thanks!!



I post this image... Should be easier to understand my problem!

Anyone can help me?



thanks in advance!!!

try this class for the Label:

[Serializable]
public class ClickText : GoText {
public override GoPartInfo GetPartInfo(GoView view, IGoPartInfoRenderer renderer) {
GoPartInfo info = renderer.CreatePartInfo();
info.ID = this.relationID;
info.SingleClick = "ShowRelation()";
return info;
}
}
Remove the GetPartInfo from the Link, and make the label Selectable.
works for me...

Please forgive me but… still don’t work because the GetPartInfo on the Text is not called clicking the MidLabel.



Please… try my code… Probably I have still something wrong… Ignore the objects like FRD_Relation, they are used to fill some property. if you need, comment the code that you don’t need.



here the link class…



[Serializable]

public class FRD_Link : GoLabeledLink

{

private ArrayList claims;

private string relationID;



public string RelationID

{

get {return relationID; }

set {relationID = value;}

}



public bool fraudulent;





public FRD_Link()

{



}





public void Initialize(FRD_Relation r, string rID)

{



this.relationID = rID;

this.fraudulent = r.Fraudolent;

FRD_Text lab = new FRD_Text();

lab.TextColor = Color.Purple;

lab.Selectable = true;

lab.Text = relationID;

this.MidLabel = lab;

this.MidLabel.Selectable = true;





Color c = (this.fraudulent) ? Color.Red : Color.Green;

DashStyle d = (this.fraudulent) ? DashStyle.Solid : DashStyle.Dot;

this.Pen = new Pen©;

this.Pen.DashStyle = d;

this.Pen.Width = 2.0F;







claims = r.GetClaims;



}





// public override GoPartInfo GetPartInfo(GoView view, IGoPartInfoRenderer renderer)

// {

//

// GoPartInfo info = renderer.CreatePartInfo();

// info[“RelationID”] = this.relationID;

// info.ID = this.relationID;

// info.SingleClick=“ShowRelationClaims()”;

// return info;

//

//

// }







public override GoContextMenu GetContextMenu(GoView view)

{

GoContextMenu cm = new GoContextMenu(view);



cm.MenuItems.Add(new GoMenuItem(“Show/Hide Claims”,“ShowContextRelationClaims(’” + this.relationID + “’)”));









return cm;

}









}



and then the Text class as you told me…







[Serializable]

public class FRD_Text : GoText

{

public override GoPartInfo GetPartInfo(GoView view, IGoPartInfoRenderer renderer)

{

GoPartInfo info = renderer.CreatePartInfo();

info.SingleClick = “ShowRelation()”;

return info;

}

}

Hi… anyone can give me help?



thanks!!

do you have a javascript function ShowRelation in your aspx file?

of course…

here the function…



function ShowRelation ()

{



if (document.getElementById(goInfo.RelationID).style.display==“none”)

{

document.getElementById(goInfo.RelationID).style.display=“block”;



}

else

{

document.getElementById(goInfo.RelationID).style.display=“none”;



}



}



function ShowContextRelationClaims (relationID)

{



if (document.getElementById(relationID).style.display==“none”)

{

document.getElementById(relationID).style.display=“block”;

goRequest(‘MyView’, ‘size=5’);

}

else

{

document.getElementById(relationID).style.display=“none”;

goRequest(‘MyView’, ‘size=2’);

}







}



I want to have the same behaviour with context menu and single click to decide what is the better.



Sorry, but when you’re debugging through a forum, you have to ask the basic questions sometimes…

> still don't work because the GetPartInfo on the Text is not called clicking the MidLabel.
The GetPartInfo is called when the GoView is prepared on the server side, not when the click happens. (I suspect you already understand that.)
Have you set breakpoints at the GetPartInfo (to be sure it's being called) and at the ShowRelation (to be sure it isn't)?

ask me everything you want… i’m here to try to understand this strange issue…



> still don’t work because the GetPartInfo on the Text is not called clicking the MidLabel.

>The GetPartInfo is called when the GoView is prepared on the server side, not when the click happens. (I suspect you already understand that.)



Yes… i’ve read on the gowebintro.doc that "The GoViewDataRenderer iterates over all of the visible objects in the view. If GoViewDataRenderer.PartInfos is true (which it is by default), it calls GoObject.GetPartInfo on each top-level object and each immediate child of GoSubGraphs. "



Is it possible that a GoText inside a GoLabeledLink is not a top-level object?



It is hard through a forum, i know… but… i’ll try again… ;)



If I override the GetPartInfo on a GoLabeledLink is all ok. when i click on the MidLabel i can go through the overridden GetPartInfo and call the javascript function.

If I override only the GetPartInfo on the GoText inserted into the MidLabel, I cannot go through the overridden GetPartInfo method on the GoText…



Hope this is more clear now…





I think that a GoText is not a top-level object…



I’ve tried to put a simple GoText object on the view.

When I click on the Text, the overridden GetPartInfo is executed while if i put it into a GoLabeledLink, isn’t executed…



I think that this is my problem…



and now the usual question…

there’s a way to execute the GetPartInfo of the GoText inside a GoLabeledLink?

Right. You have to create the GoPartInfo for the MidLabel when the GoLabeledLink.GetPartInfo is called.

using that ClickText class for the label (the code above), make your LabeledLink GetPartInfo look like this:
public override GoPartInfo GetPartInfo(GoView view, IGoPartInfoRenderer renderer) {
if (this.MidLabel is ClickText) {
ClickText t = this.MidLabel as ClickText;
return t.GetPartInfo(view, renderer);
}
return null;
}