1,105,226 Community Members

Getting text in textbox(in webbrowser control)

Member Avatar
yoksu
Newbie Poster
3 posts since Sep 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi.

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?

Member Avatar
alok.patoria123
Newbie Poster
1 post since Sep 2009
Reputation Points: -2 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
-1
 

very simple dude...
String str=Textbox.Text
insert Str through insert query in db.

Member Avatar
yoksu
Newbie Poster
3 posts since Sep 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

serkan sendur
Postaholic
2,057 posts since Jan 2008
Reputation Points: 821 [?]
Q&As Helped to Solve: 129 [?]
Skill Endorsements: 1 [?]
Banned
 
1
 

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()
		{
			InitializeComponent();
		}

		private void btnGetText_Click(object sender, EventArgs e)
		{
			MessageBox.Show(webBrowser1.Document.GetElementById("textbox").GetAttribute("value"));
		}

		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))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		#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();
			this.SuspendLayout();
			// 
			// 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.Controls.Add(this.btnGetText);
			this.Controls.Add(this.webBrowser1);
			this.Name = "Form1";
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}

		#endregion

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

pageWithTextBox.htm :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<title></title>
	</head>
	<body>
        <input id="textbox" type="text" />
	
	</body>
</html>
Attachments GetTextInTextBox.zip (32.56KB)
Member Avatar
yoksu
Newbie Poster
3 posts since Sep 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks a lot serkan. It is worked.

serkan sendur
Postaholic
2,057 posts since Jan 2008
Reputation Points: 821 [?]
Q&As Helped to Solve: 129 [?]
Skill Endorsements: 1 [?]
Banned
 
0
 

please mark this as solved

Question Answered as of 4 Years Ago by serkan sendur and alok.patoria123
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article