web browser's Browser_DocumentCompleted event is firing only first time,plz help

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 12
Reputation: ashu2409 is an unknown quantity at this point 
Solved Threads: 0
ashu2409 ashu2409 is offline Offline
Newbie Poster

web browser's Browser_DocumentCompleted event is firing only first time,plz help

 
-1
  #1
18 Days Ago
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 ---------
  1. public void myFunction()
  2. {
  3. System.Windows.Forms.WebBrowser Browser = new WebBrowser();
  4. clsErrorLog.WriteLog("goes for browser");
  5. Uri url = new Uri("my_url");
  6. Browser.Url = url;
  7. Browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Browser_DocumentCompleted);
  8. Browser.Visible = true;
  9. Browser.Size = new System.Drawing.Size(758, 539);
  10.  
  11. }
  12. --this is event
  13. private void Browser_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
  14. {
  15.  
  16. System.Windows.Forms.WebBrowser Browser = (System.Windows.Forms.WebBrowser)sender;
  17. this.Controls.Add(Browser);
  18.  
  19. HtmlDocument Doc;
  20. Doc = Browser.Document;
  21.  
  22. int LastPagerIndex = 0;
  23. Boolean ChkAltBtn = true;
  24. string AltPagerText = "";
  25.  
  26.  
  27. string ctlType = "";
  28. ctlType = "a";
  29. Boolean IsAnchor = true;
  30. if (IsAnchor)
  31. {
  32. if (ctlType.Trim().Length > 0)
  33. {
  34. HtmlElementCollection ctl = Doc.GetElementsByTagName(ctlType);
  35. if (ctl != null)
  36. {
  37. for (int i = 0; i < ctl.Count; i++)
  38. {
  39. if (ctl[i].InnerText != null)
  40. {
  41. if (ctl[i].InnerText.Trim() == (PagerBtnText - 2).ToString())
  42. {
  43. LastPagerIndex = i;
  44. }
  45.  
  46. if (ctl[i].InnerText.Trim() == PagerBtnText.ToString())
  47. {
  48.  
  49. ctl[i].InvokeMember("Click");
  50. ChkAltBtn = false;
  51. Browser.Show();
  52.  
  53. }
  54. }
  55. }
  56.  
  57. }
  58. }
  59. PagerBtnText++;
  60. }

Please help me....
Reply With Quote Quick reply to this message  
Reply

Tags
browser, web

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC