I can not find the error in this program

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            webBrowser1.Navigate(" http://www.httpsurf.com/ ");

    //the debugger tells me that the error in this line     
          webBrowser1.Document.GetElementById("url").InnerText = textBox1.Text;

            webBrowser1.Document.GetElementById("go").InvokeMember("Click");
       
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}

You are not giving the webBrowser component enough time to load, before you try to set the properties of the HTML document. Try using another button, like this:

private void button1_Click(object sender, EventArgs e)
{
    // lets the browser control load up
    webBrowser1.Navigate(" http://www.httpsurf.com/ ");
}

private void button2_Click(object sender, EventArgs e)
{
    // Now, all of the info should now be in the document and ready to go
    webBrowser1.Document.GetElementById("url").InnerText = textBox1.Text;
    webBrowser1.Document.GetElementById("go").InvokeMember("Click");
}
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.