943,721 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 6747
  • C# RSS
Sep 25th, 2009
0

Getting text in textbox(in webbrowser control)

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yoksu is offline Offline
3 posts
since Sep 2009
Sep 25th, 2009
-1

Re: Getting text in textbox(in webbrowser control)

very simple dude...
String str=Textbox.Text
insert Str through insert query in db.
Reputation Points: 8
Solved Threads: 1
Newbie Poster
alok.patoria123 is offline Offline
1 posts
since Sep 2009
Sep 25th, 2009
0

Re: Getting text in textbox(in webbrowser control)

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yoksu is offline Offline
3 posts
since Sep 2009
Sep 25th, 2009
1

Re: Getting text in textbox(in webbrowser control)

see the attached project too :
Form1.cs :

C# Syntax (Toggle Plain Text)
  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. using System.IO;
  9. using System.Reflection;
  10.  
  11. namespace GetTextInTextBox
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. private void btnGetText_Click(object sender, EventArgs e)
  21. {
  22. MessageBox.Show(webBrowser1.Document.GetElementById("textbox").GetAttribute("value"));
  23. }
  24.  
  25. private void Form1_Load(object sender, EventArgs e)
  26. {
  27. webBrowser1.Url = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "pageWithTextBox.htm"));
  28.  
  29. }
  30. }
  31. }

Form1.Designer.cs :

C# Syntax (Toggle Plain Text)
  1. namespace GetTextInTextBox
  2. {
  3. partial class Form1
  4. {
  5. /// <summary>
  6. /// Required designer variable.
  7. /// </summary>
  8. private System.ComponentModel.IContainer components = null;
  9.  
  10. /// <summary>
  11. /// Clean up any resources being used.
  12. /// </summary>
  13. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  14. protected override void Dispose(bool disposing)
  15. {
  16. if (disposing && (components != null))
  17. {
  18. components.Dispose();
  19. }
  20. base.Dispose(disposing);
  21. }
  22.  
  23. #region Windows Form Designer generated code
  24.  
  25. /// <summary>
  26. /// Required method for Designer support - do not modify
  27. /// the contents of this method with the code editor.
  28. /// </summary>
  29. private void InitializeComponent()
  30. {
  31. this.webBrowser1 = new System.Windows.Forms.WebBrowser();
  32. this.btnGetText = new System.Windows.Forms.Button();
  33. this.SuspendLayout();
  34. //
  35. // webBrowser1
  36. //
  37. this.webBrowser1.Location = new System.Drawing.Point(25, 12);
  38. this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
  39. this.webBrowser1.Name = "webBrowser1";
  40. this.webBrowser1.Size = new System.Drawing.Size(250, 250);
  41. this.webBrowser1.TabIndex = 0;
  42. this.webBrowser1.Url = new System.Uri("", System.UriKind.Relative);
  43. //
  44. // btnGetText
  45. //
  46. this.btnGetText.Location = new System.Drawing.Point(305, 35);
  47. this.btnGetText.Name = "btnGetText";
  48. this.btnGetText.Size = new System.Drawing.Size(75, 23);
  49. this.btnGetText.TabIndex = 1;
  50. this.btnGetText.Text = "Get Text";
  51. this.btnGetText.UseVisualStyleBackColor = true;
  52. this.btnGetText.Click += new System.EventHandler(this.btnGetText_Click);
  53. //
  54. // Form1
  55. //
  56. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  57. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  58. this.ClientSize = new System.Drawing.Size(454, 291);
  59. this.Controls.Add(this.btnGetText);
  60. this.Controls.Add(this.webBrowser1);
  61. this.Name = "Form1";
  62. this.Text = "Form1";
  63. this.Load += new System.EventHandler(this.Form1_Load);
  64. this.ResumeLayout(false);
  65.  
  66. }
  67.  
  68. #endregion
  69.  
  70. private System.Windows.Forms.WebBrowser webBrowser1;
  71. private System.Windows.Forms.Button btnGetText;
  72. }
  73. }

pageWithTextBox.htm :

C# Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3. <head>
  4. <title></title>
  5. </head>
  6. <body>
  7. <input id="textbox" type="text" />
  8.  
  9. </body>
  10. </html>
Attached Files
File Type: zip GetTextInTextBox.zip (32.6 KB, 235 views)
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
Sep 26th, 2009
0

Re: Getting text in textbox(in webbrowser control)

Thanks a lot serkan. It is worked.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yoksu is offline Offline
3 posts
since Sep 2009
Sep 26th, 2009
0

Re: Getting text in textbox(in webbrowser control)

please mark this as solved
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Adding Row To DatagridView
Next Thread in C# Forum Timeline: Mounting ISO in C#





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC