Jump to content
Software FX Community

Is possible to add a custom toolbar item that will call a client side javascript function?


Fred

Recommended Posts

I'm using .Net RenderFormat. I added the new ToolBarItem associated with my custom Command. I set

command.Script = "alert('Test');"; but the alert function never gets called.

command.Script = "alert('Test');"; but the alert function never gets called.

 

Thanks.

Link to comment
Share on other sites

The Script property takes the name of the JavaScript fuction to be executed, not an actual javascript fragment. For example:

  cmd.Script = "MyCommand";

will call:

  function MyCommand (commandId)   {   alert(commandId);   }

Notice the commandId parameter that will be passed to the function.

Link to comment
Share on other sites

It still doen't work if I switch to use the name of Javascript function. Here is what I have in my aspx.cs

Command command = new Command(Convert.ToInt32(MyCustomCommandId));

Command command = new Command(Convert.ToInt32(MyCustomCommandId));

command.Text = "Test";

command.Style = CommandStyles.ShowTextOnly;

"Test";

command.Style = CommandStyles.ShowTextOnly;

CommandStyles.ShowTextOnly;

command.Script = "Button1_onclick";

"Button1_onclick";

Chart1.Commands.Add(command);

ToolBarItem tbi = new ToolBarItem(MyCustomCommandId);

ToolBarItem tbi = new ToolBarItem(MyCustomCommandId);

Chart1.ToolBar.Insert(0, tbi);

Here is the javascript code on aspx page:

function Button1_onclick(commandId)

{

alert(commandId);

}

the javascript function never gets called when i push the new button. Is there anything wrong with my code? Thanks!

Fred

 

Button1_onclick(commandId)

{

alert(commandId);

}

the javascript function never gets called when i push the new button. Is there anything wrong with my code? Thanks!

Fred

 

Link to comment
Share on other sites

Sorry the Quick reply doen't handle copy&paste very well, here is the correct post:

It still doen't work if I switch to use the name of Javascript function. Here is what I have in my aspx.cs

Command command = new Command(Convert.ToInt32(MyCustomCommandId));

command.Text = "Test";command.Style = CommandStyles.ShowTextOnly;command.Script = "Button1_onclick";

Chart1.Commands.Add(command);

ToolBarItem tbi = new ToolBarItem(MyCustomCommandId);Chart1.ToolBar.Insert(0, tbi);

 

Here is the javascript code on aspx page:

function Button1_onclick(commandId)

{

 alert(commandId);

}

the javascript function never gets called when i push the new button. Is there anything wrong with my code? Thanks!

Fred

 

Link to comment
Share on other sites

Are you generating an Image or a .NET Client control?

The Script property is only for interactive images, if you are using the .NET Client Control you have to process the UserCommand event in your JavaScript instead.

Note, in order to capture events from your .NET Client Control your .NET Security settings need to be set to Full Trust.

Link to comment
Share on other sites

I'm generating a .Net client control. So I have to catch UserCommand event in Javascript. Do you have some sample code that I can take as reference? Regarding to setting .NET Security to Full Trust, is it enough to follow the procedure to ChartFX.WebForms.dll and choose tp apply to all asseblies with the same public key and uncheck the "Include version" option as described in this article http://support.softwarefx.com/Article.aspx?KBID=6141001&Product=CfxNet62&Embed=1 ?

Thanks.

 

Fred

Link to comment
Share on other sites

Here is a sample JavaScript that captures the user command event and process it:

<script  language="JavaScript" for="Chart1" event="UserCommand(sender, args)"><!-- if (args.CommandId == 1) {   alert("Custom Command 1"); }--></script>

 As for the Full Trust issue, yes, as long as you authorize the client control to run in the client machine, it doesn't matter how, it can be using the strong name, the site, the zone or the specific assembly. Note that the assembly version of the .NET Client control changes from service pack to service pack.

post-2613-13922400360066_thumb.jpg

Link to comment
Share on other sites

The Chart FX .NET Client.

I suggest that to try first, grant full permission to the entire zone, then once you get it working you can do it more granular as explained in the KB article.

Note that I am talking about the security settings in the client computer, not the server.

Link to comment
Share on other sites

  • 2 weeks later...

Thanks for the code, Frank. I finally made it to work. The reason it didn't work is that Asp.Net messed the ControlID around when you use a page inherited from a MasterPage. So once I switched to use

<script language="JavaScript" for='<%=Chart1.UniqueID%>' event="UserCommand(sender, args)">

rather than

<script language="JavaScript" for="Chart1" event="UserCommand(sender, args)">

Everything started working properly.

Thank you again for all the help Frank!

 

 Fred

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...