Hello,
I'm an ASP.NET developer attempting to make my first Windows Forms application, and it's not going so well.
What I'm trying to do is programmatically fill in and submit an online form via a WebBrowser Control. I've researched this for hours already and found some example code, but nothing for my particular situation except the code found here: All About Microsoft.Net Technologies!: Programmatically input data on a form and click submit button using C#
I'm getting a NullReferenceException ("object reference not set to an instance of an object") for each of the two lines (which I tested separately) after WebBrowser1.Navigate(startSite). I've dealt with this error in ASP.NET, but I don't understand what the problem is in this particular context.
Here's my code:
------------------ Form1.vb ------------------
------------------ somepage.aspx ------------------
(some code omitted for brevity)
I'd like the user to enter their email into a TextBox on Form1, press a button, and have an invisible WebBrowser navigate to the desired page and submit the form.
Any help with this would be greatly appreciated. Thanks in advance.
I'm an ASP.NET developer attempting to make my first Windows Forms application, and it's not going so well.
What I'm trying to do is programmatically fill in and submit an online form via a WebBrowser Control. I've researched this for hours already and found some example code, but nothing for my particular situation except the code found here: All About Microsoft.Net Technologies!: Programmatically input data on a form and click submit button using C#
I'm getting a NullReferenceException ("object reference not set to an instance of an object") for each of the two lines (which I tested separately) after WebBrowser1.Navigate(startSite). I've dealt with this error in ASP.NET, but I don't understand what the problem is in this particular context.
Here's my code:
------------------ Form1.vb ------------------
VB.NET:
Public Class Form1
Const startSite As String = "http://www.somesite.com/somepage.aspx"
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
WebBrowser1.Hide()
WebBrowser1.Navigate(startSite)
WebBrowser1.Document.GetElementById("TextBox1").SetAttribute("Text", TextBox1.Text)
WebBrowser1.Document.GetElementById("Button1").InvokeMember("click")
End Sub
End Class
------------------ somepage.aspx ------------------
(some code omitted for brevity)
VB.NET:
<form id="form1" runat="server">
<div>
Enter your email:<br />
<br />
<asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox><br />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" /></div>
</form>
I'd like the user to enter their email into a TextBox on Form1, press a button, and have an invisible WebBrowser navigate to the desired page and submit the form.
Any help with this would be greatly appreciated. Thanks in advance.