473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to get a title of a page displayed in webbrowser control in c# ?

8
Hi All ,
Any one please help me in getting a title of a page displayed in webbrowser control in c# .The title needs to be displayed in lable in a windows form which has this webcontrol intit.I tried with HTMLTitleElementClass but it's not returning anything.
Then I tried with DocumentTitle property which should display the title of the document currently displayed in the WebBrowser control. But Hard luck ... This also failed.

Any Help in this is appreciated.

Cheers,
Jon
Jul 17 '08 #1
13 5897
Plater
7,872 Expert 4TB
This did not work?
Expand|Select|Wrap|Line Numbers
  1. myWebbrowser.Document.Title
  2.  
Jul 17 '08 #2
Jon86
8
This did not work?
Expand|Select|Wrap|Line Numbers
  1. myWebbrowser.Document.Title
  2.  
I already tried Document.Title... HARD LUCK ...

Please help
Jul 17 '08 #3
Plater
7,872 Expert 4TB
Are you sure the document HAS a title?
Jul 17 '08 #4
Are you using an ASP.Net Front end or an empty Web Site?


btw Plater and Alias this forum would be lost without you both. Plus I like seeing the preformatted MODERATOR messages.
Jul 17 '08 #5
Jon86
8
Are you sure the document HAS a title?
Yes of course the page is having a title .... It's not showing title for any sites/page.
Jul 17 '08 #6
Plater
7,872 Expert 4TB
Weird. I just ran it and it gave me the title just fine.
You are waiting until the Navigated event has fired before looking for a title right?

Here's what I just tried.
Expand|Select|Wrap|Line Numbers
  1. private bool cango = false;
  2. private string GetTitle(string url)
  3. {
  4.    string retval = "";
  5.    cango = false;
  6.    myWebBrowser.Navigate(url);
  7.    while (!cango)
  8.    {
  9.       Application.DoEvents();
  10.    }
  11.    cango = false;
  12.    retval = myWebBrowser.Document.Title;
  13.    return retval;
  14. }
  15.  
  16. void wb_Navigated(object sender, WebBrowserNavigatedEventArgs e)
  17. {
  18.    cango = true;
  19. }
  20.  
Now since you're actually using the webpage, I would just do this:
Expand|Select|Wrap|Line Numbers
  1. void wb_Navigated(object sender, WebBrowserNavigatedEventArgs e)
  2. {
  3.    myLabel.Text=myWebBrowser.Document.Title;
  4. }
  5.  
Jul 17 '08 #7
Jon86
8
Are you using an ASP.Net Front end or an empty Web Site?


btw Plater and Alias this forum would be lost without you both. Plus I like seeing the preformatted MODERATOR messages.

The title needs to be displayed in label in a windows form which has this webcontrol in it
Jul 17 '08 #8
Curtis Rutland
3,256 Expert 2GB
btw Plater and Alias this forum would be lost without you both. Plus I like seeing the preformatted MODERATOR messages.
Why thank you! Nice to know that we are appreciated
:D
Jul 17 '08 #9
Jon86
8
Weird. I just ran it and it gave me the title just fine.
You are waiting until the Navigated event has fired before looking for a title right?

Here's what I just tried.
Expand|Select|Wrap|Line Numbers
  1. private bool cango = false;
  2. private string GetTitle(string url)
  3. {
  4.    string retval = "";
  5.    cango = false;
  6.    myWebBrowser.Navigate(url);
  7.    while (!cango)
  8.    {
  9.       Application.DoEvents();
  10.    }
  11.    cango = false;
  12.    retval = myWebBrowser.Document.Title;
  13.    return retval;
  14. }
  15.  
  16. void wb_Navigated(object sender, WebBrowserNavigatedEventArgs e)
  17. {
  18.    cango = true;
  19. }
  20.  
Now since you're actually using the webpage, I would just do this:
Expand|Select|Wrap|Line Numbers
  1. void wb_Navigated(object sender, WebBrowserNavigatedEventArgs e)
  2. {
  3.    myLabel.Text=myWebBrowser.Document.Title;
  4. }
  5.  



Hi,
This is what I tried with the piece of code you send .....still the label is blank ...
Can you please guide me on this...

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8.  
  9. namespace testwinform
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.  
  18.         private void button1_Click(object sender, EventArgs e)
  19.         {
  20.             string url=textBox1.Text;
  21.             GetTitle(url);
  22.  
  23.  
  24.         }
  25.  
  26.         private bool cango = false;
  27.         private string GetTitle(string url)
  28.         {
  29.             string retval = "";
  30.             cango = false;
  31.             webBrowser1.Navigate(url);
  32.             while (!cango)
  33.             {
  34.                 Application.DoEvents();
  35.             }
  36.             cango = false;
  37.             retval = webBrowser1.Document.Title;
  38.             return retval;
  39.         }
  40.  
  41.         void wb_Navigated(object sender, WebBrowserNavigatedEventArgs e)
  42.         {
  43.             cango = true;
  44.  
  45.             label1.Text = webBrowser1.Document.Title;
  46.         }
  47.  
  48.  
  49.  
  50.     }
  51. }
  52.  

Appreciate your help,
Jon
Jul 17 '08 #10
Curtis Rutland
3,256 Expert 2GB
Please use the [code] tags when posting your code. It makes it easier for the experts to read, and the easier, the better and faster you get help. Please read the Posting Guidelines.

MODERATOR
Jul 17 '08 #11
Plater
7,872 Expert 4TB
Did you remember to attach that wb_navigated handler function to the navigated event on your webbrowser control?
Jul 17 '08 #12
Jon86
8
Did you remember to attach that wb_navigated handler function to the navigated event on your webbrowser control?
yes buddy .. i created the navigated event handler ..
Jul 18 '08 #13
Plater
7,872 Expert 4TB
yes buddy .. i created the navigated event handler ..
Well then I don't know what to tell you. You must be doing something different somewhere.
I did it in like 3mins and it worked just fine.
Jul 18 '08 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mark | last post by:
I am at my wits' end. I have the following code: WebBrowser1.Navigate ("c:\path\page.htm") Text1.Text = WebBrowser1.Document.Links.length Where the page.htm has the following HTML: <html>
3
by: Olivier/Noetika | last post by:
Hi, Inside my application, I have a form that is composed with a listview and a webbrowser. The webbrowser display the focused url contained in the list view. The problem is that this works the...
2
by: Spencer | last post by:
I am using the WebBrowser control in .NET 2.0 but it is throwing an error when trying to run a html page that has some JScript and an applet within it. The page runs fine via a standard IE 6.0...
12
by: Alex Clark | last post by:
Greetings, (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs). I've decided to take advantage of the layout characteristics of HTML documents to simplify my printing tasks, but...
1
by: JP2006 | last post by:
I'm trying to write a control that will take a screen capture of a particular website when a user submits a form in a web application; one of the form fields is for a URL - the control needs to get...
0
by: =?Utf-8?B?c25naWxi?= | last post by:
I am having 3 issues with the WebBrowser control which may all be related. The HTML for the page is the standard Weather Magnet from weather.com. The actual HTML is at the bottom of this page. ...
2
by: Scott Gravenhorst | last post by:
I recently (within 30 days) downloaded and installed VB 2005 Express. I like it a whole lot... but: I have been trying to work with the WebBrowser control to display a small amount of help text...
2
by: jim | last post by:
Has anyone seen a way to read the data stream for a URL being navigated to by a webbrowser control and edit it (i.e. search HTML stream for and possibly remove objectionable language for a kid's...
3
by: BryanGilbert | last post by:
Hello everyone, I am developing one win application which makes use of WebBrowser control.I am passing the url in a text box and the page is getting displayed in the web browser control.Till this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.