I am using a webbrowser control in my form program and i am displaying an html page. There is 1 textbox in html page and id is "textbox". When someone write something in textbox, i want to use this text and save it to db. It will be work like this; somebody is writing somethings in textbox(in html page) and when press the button(form button), i want to save this text.

How can i do that?

7 Years
Discussion Span
Last Post by serkan sendur

Alok, I think you didnt read carefully(:

The textbox is in html page. There is a webbrowser control and it has a textbox(in html page) and then in form, there is a button. When a user write "example" in textbox(in html page), and then click the button, I want to catch this "example".

string txt = ...................; ----> txt must be what user write in textbox.


see the attached project too :
Form1.cs :

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

namespace GetTextInTextBox
	public partial class Form1 : Form
		public Form1()

		private void btnGetText_Click(object sender, EventArgs e)

		private void Form1_Load(object sender, EventArgs e)
			webBrowser1.Url = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "pageWithTextBox.htm"));


Form1.Designer.cs :

namespace GetTextInTextBox
	partial class Form1
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
			if (disposing && (components != null))

		#region Windows Form Designer generated code

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
			this.webBrowser1 = new System.Windows.Forms.WebBrowser();
			this.btnGetText = new System.Windows.Forms.Button();
			// webBrowser1
			this.webBrowser1.Location = new System.Drawing.Point(25, 12);
			this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
			this.webBrowser1.Name = "webBrowser1";
			this.webBrowser1.Size = new System.Drawing.Size(250, 250);
			this.webBrowser1.TabIndex = 0;
			this.webBrowser1.Url = new System.Uri("", System.UriKind.Relative);
			// btnGetText
			this.btnGetText.Location = new System.Drawing.Point(305, 35);
			this.btnGetText.Name = "btnGetText";
			this.btnGetText.Size = new System.Drawing.Size(75, 23);
			this.btnGetText.TabIndex = 1;
			this.btnGetText.Text = "Get Text";
			this.btnGetText.UseVisualStyleBackColor = true;
			this.btnGetText.Click += new System.EventHandler(this.btnGetText_Click);
			// Form1
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.ClientSize = new System.Drawing.Size(454, 291);
			this.Name = "Form1";
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);



		private System.Windows.Forms.WebBrowser webBrowser1;
		private System.Windows.Forms.Button btnGetText;

pageWithTextBox.htm :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
        <input id="textbox" type="text" />
Votes + Comments
Very instructive!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.