从C调用onclick方法#
我想调用C#中的onclick。我把一个WebBrowser到基于C#的程序,并在网站上,有一个js
功能从C调用onclick方法#
type="button"
onclick="submitEdgeStory();"
value="Invia la news" class="submit"
我想打电话给onclick
方法绑一个按钮。我试着打电话给submitEdgeStory
有:
webBrowser1.Document.InvokeScript("submitEdgeStory()");
或
webBrowser1.Document.Forms[1]
.SetAttribute("onclick", "return submitEdgeStory()");
但没办法..我不知道我怎么可以调用这个函数...
PS:我不使用ASP.NET
。这只是一个桌面应用程序
而且也这是js函数
var gPageIsOkToExit = false;
function submitEdgeStory()
{
// Set a variable so that our "before unload" exit handler knows not to verify
// the page exit operation.
gPageIsOkToExit = true;
// Do the submission.
// var frm = document.getElementById("thisform");
frms = document.getElementsByName("ATISUBMIT");
if (frms)
{
if (frms[0])
frms[0].submit();
}
}
window.onbeforeunload = function (event)
{
// See if this is a safe exit.
if (gPageIsOkToExit)
return;
if (!event && window.event)
event = window.event;
event.returnValue = "You have not hit the Submit Button to submit your story yet.";
}
我解决它像你使用的是哪个web浏览器这样
foreach (HtmlElement item in webBrowser1.Document.All)
{
if (item.OuterHtml != null)
{
if (item.OuterHtml.Contains("submitEdgeStory"))
{
item.InvokeMember("click");
break;
}
}
}
如果您分配一个ID,您的按钮
type="button"
onclick="submitEdgeStory();"
value="Invia la news" class="submit" id="buttonid"
,那么你可以做 -
WebBrowser1.Document.GetElementById("buttonid").InvokeMember("submit")
webBrowser.Document.Forms[0].All.GetElementsByName("buttonname")[0].InvokeMember("click");
应该工作正常。
heyy thanx它的作品:)但我不知道按钮名称,然后我用[代码]列表
? WinForms之一,WPF之一,还是Silverlight之一? –
我使用winform .. – ertan2002