Must be something else you're doing ( wrong maybe ;) ). I threw toghether this small example and it works exactly as expected:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TestWebBrowser
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.DocumentText = "<html><head><title></title></head><body><a href=\"#\" onClick=\"alert('yeah');\">Click Me</a></body></html>";
}
}
}
A simple form with a
WebBrowser
control on it and a button that makes the control load the
HTML
you provided via
DocumentText
. The form shows the ClickMe link and when I click it the alert box springs up with "yeah".
Best Regards,
--MRB