Getting text in textbox(in webbrowser control)

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2009
Posts: 3
Reputation: yoksu is an unknown quantity at this point 
Solved Threads: 0
yoksu yoksu is offline Offline
Newbie Poster

Getting text in textbox(in webbrowser control)

 
0
  #1
Sep 25th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 1
Reputation: alok.patoria123 is an unknown quantity at this point 
Solved Threads: 0
alok.patoria123 alok.patoria123 is offline Offline
Newbie Poster

Re: Getting text in textbox(in webbrowser control)

 
-1
  #2
Sep 25th, 2009
very simple dude...
String str=Textbox.Text
insert Str through insert query in db.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 3
Reputation: yoksu is an unknown quantity at this point 
Solved Threads: 0
yoksu yoksu is offline Offline
Newbie Poster

Re: Getting text in textbox(in webbrowser control)

 
0
  #3
Sep 25th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Getting text in textbox(in webbrowser control)

 
1
  #4
Sep 25th, 2009
see the attached project too :
Form1.cs :

  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 :

  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 :

  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, 6 views)
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 3
Reputation: yoksu is an unknown quantity at this point 
Solved Threads: 0
yoksu yoksu is offline Offline
Newbie Poster

Re: Getting text in textbox(in webbrowser control)

 
0
  #5
Sep 26th, 2009
Thanks a lot serkan. It is worked.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Getting text in textbox(in webbrowser control)

 
0
  #6
Sep 26th, 2009
please mark this as solved
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC