ashu2409 0 Newbie Poster

Hi all,

I have a window service from which i am calling a windows application in c#.
and i am using web browser in window application to get html from a link,
but problem is that web browser's Browser_DocumentCompleted event is firing only first time when service calls application,only for the first page, it is not going on second page,not firing again,

but if we run the application alone it fires till the end of paging....working fine....

but i have to call it from service.
this is the code ---------

public void myFunction()
{
System.Windows.Forms.WebBrowser Browser = new WebBrowser();
            clsErrorLog.WriteLog("goes for browser");
            Uri url = new Uri("my_url");
             Browser.Url = url;                     
            Browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Browser_DocumentCompleted);
            Browser.Visible = true;
            Browser.Size = new System.Drawing.Size(758, 539);

}
--this is event
private void Browser_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
        {

            System.Windows.Forms.WebBrowser Browser = (System.Windows.Forms.WebBrowser)sender; 
                this.Controls.Add(Browser);
            
                HtmlDocument Doc;
                Doc = Browser.Document;
            
                int LastPagerIndex = 0;
                Boolean ChkAltBtn = true;
                string AltPagerText = "";

               
                string ctlType = "";                
                ctlType = "a";
                Boolean IsAnchor = true;
                if (IsAnchor)
                {
                    if (ctlType.Trim().Length > 0)
                    {
                        HtmlElementCollection ctl = Doc.GetElementsByTagName(ctlType);
                        if (ctl != null)
                        {
                            for (int i = 0; i < ctl.Count; i++)
                            {
                                if (ctl[i].InnerText != null)
                                {
                                    if (ctl[i].InnerText.Trim() == (PagerBtnText - 2).ToString())
                                    {
                                        LastPagerIndex = i;
                                    }

                                    if (ctl[i].InnerText.Trim() == PagerBtnText.ToString())
                                    {
                                      
                                        ctl[i].InvokeMember("Click");
                                        ChkAltBtn = false;
                                        Browser.Show();
                                     
                                    }
                                }
                            }
                           
                        }
                    }
                    PagerBtnText++;                   
                }

Please help me....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.