winforms 如何在Winform的Web浏览器控件中触发__dopastback()

jk9hmnmh  于 2022-12-23  发布在  其他
关注(0)|答案(1)|浏览(176)

我正试图在WinForms中操纵一个URL的html用于自动化目的,在网页上有一个锚标记:

<Ahref="javascript:__doPostBack('dgBloodDonorResults$ctl01$ctl01','')">2</A>

如何自动触发__dopostback()?
我试过这个:

mshtml.HTMLDocument doc = (mshtml.HTMLDocument)webBrowser1.Document.DomDocument;

            mshtml.IHTMLElementCollection anchors = doc.getElementsByTagName("a");

            foreach (mshtml.IHTMLElement anchorElement in anchors)
            {
                mshtml.HTMLAnchorElement anchor = anchorElement as mshtml.HTMLAnchorElement;
                if (anchor != null)
                {
                    string outerHTML = anchor.outerHTML;

                    if (outerHTML.Contains("dgBloodDonorResults$"))
                    {
                      
                        if (currentGridPage +1 <= totalPagesInGrid)
                        {
                            currentGridPage++;
                            System.Diagnostics.Debug.WriteLine(anchor.href + " HTML: " + outerHTML);

                            anchor.click(); //I Want this to firing.

                          
                        }
                        else
                        {
                            isPostback = false;
                            currentGridPage = 0;
                            return;
                        }
                        //UpdateBrowser();
                    }
                }
            }
           `
vwkv1x7d

vwkv1x7d1#

您可以直接调用该方法:

webBrowser1.Document.InvokeScript("__doPostBack", 
      new object [] { "dgBloodDonorResults$ctl01$ctl01", "" } 
    );

MSDN上的文档

相关问题