HTML脚本标记包含函数
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
我需要从C#执行javascript。我的代码:
var webbrowser = new WebBrowser();
var uri = new Uri(param.FinalUrl);
webbrowser.Navigate(uri);
while (webbrowser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
Thread.Sleep(100);
}
var args = new object[] { "ctl00$cphBody$gvTradeList", "Page$3" };
var result = webbrowser.Document.InvokeScript("__doPostBack", args);
但InvokeScript始终返回null并且DocumentText不会更改。该问题可能是由CDATA标签中的注释引起的吗?如果这是原因,在这种情况下如何执行javascript?