Hi all,
I am generating a html report displaying the records. In that report their are 10 rows and 4 columns. In 4th column i am adding the button. Now i want to use button click event i.e onclick() .
1) how i call the javascript function/Javascript.
2) how can i get button click 1st column in particular row value.


Thanks In Advance

Dani AI

Generated

Quick practical summary and fixes that extend the replies from , , , and .

For an HTML report shown inside your Windows app the simplest approach is to host the page in a WebBrowser control and let the page’s JavaScript handle the click. That keeps DOM logic in the HTML (easy to inspect and debug) while the app can call into the page or the page can call back into the app when needed. (learn.microsoft.com)

Example: use event delegation so every table button doesn’t need its own inline handler (works when rows are generated dynamically):

document.addEventListener('click', function(e) {
  if (!e.target.matches('button.row-btn')) return;
  var tr = e.target.closest('tr');
  var firstCell = tr && tr.querySelector('td');
  var id = firstCell ? firstCell.textContent.trim() : null;
  // now use id (send to server, call window.external, etc.)
});

If the host app needs to call JavaScript functions, use HtmlDocument.InvokeScript after the page finishes loading. To call into .NET from JavaScript expose a COM-visible object via WebBrowser.ObjectForScripting and call it as window.external. Remember to set ObjectForScripting only after the control is created and mark the target class [ComVisible(true)]. (learn.microsoft.com)

About the Microsoft.JScript error you hit: trying to compile/execute JScript via CodeDomProvider relies on legacy assemblies and can be brittle. For in-process script hosting consider modern, supported alternatives such as Jint (pure C# JS interpreter) or ClearScript (V8 or JScript engines) instead of fighting assembly-binding problems. These projects are actively maintained and easier to deploy. Also keep security in mind: do not expose sensitive host objects to untrusted HTML/scripts. (github.com)

If you prefer a pure Windows control (no HTML), ’s DataGridView suggestion remains valid when you only need tabular UI and .NET-side events.

Recommended Answers

All 8 Replies

Why not use a DatagridView instead?

Hello ddanbe,
Actually i am looking for HTML Report.

write onclick="javascript:funcitonname();" in button tag and call funcitonname() function

Hi adatapost i am used this
1. http://social.msdn.microsoft.com/for...d-b45815e32c7c

provider = (CodeDomProvider)Activator.CreateInstance("Microsoft.Jscript", "Microsoft.Jscript.JScriptCodeProvider").Unwrap();

but it will give me an error
like

Could not load file or assembly 'Microsoft.Jscript' or one of its dependencies. The system cannot find the file specified.

i am used the namespaces are

using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections;
using System.Reflection;
using Microsoft.JScript;
using Microsoft.JScript.Vsa;

Does Anybody help me?

Thanks in advance

Thanks all for replying.......

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.