Sourabh Sashank
Sourabh Sashank

Reputation: 300

How to Fire __dopastback() in Winform's Webbrowser Control

I am trying to manipulate html of a url in WinForms for automation purpose, On the webpage there is an anchor tag:

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

How can I fire __dopostback() automatically??

I tried this:

           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();
                    }
                }
            }
           `

Upvotes: 0

Views: 385

Answers (1)

Jcl
Jcl

Reputation: 28272

You can directly invoke the method:

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

Documentation on MSDN

Upvotes: 0

Related Questions