-1

I want to inject this commands on webbrowser.. How I can do it?

oFormObject = document.forms['formid'];  
oFormObject.elements["name"].value = 'Some Value';
document.getElementById('formid').submit();
stefy97100
  • 41
  • 7

1 Answers1

1

You need to read up on ClientScriptManager.RegisterClientScriptBlock.

StringBuilder csText = new StringBuilder();
      csText.Append("<script type=\"text/javascript\"> function DoClick() {");
      csText.Append("Form1.Message.value='Text from client script.'} </");
      csText.Append("script>");
      cs.RegisterClientScriptBlock(csType, csName, csText.ToString());
James Hill
  • 60,353
  • 20
  • 145
  • 161
  • Ok, and how i can simulate the submit button of the form? (i'm using c# forms) – stefy97100 Jul 06 '14 at 13:35
  • That's a totally different question than `How do I inject this JS into a form?`. I suggest you post a new question, including what you've tried. Also, you should consider accepting answers that help you, and read up on how to ask a question: http://stackoverflow.com/questions/how-to-ask. With that being said, the code you've posted should work using the method I've provided. Try it, play with it. Learn. - `document.getElementById('formid').submit();` – James Hill Jul 06 '14 at 13:37
  • I use this command: webBrowser2.Document.GetElementById('formid').submit(); but not work – stefy97100 Jul 06 '14 at 14:05
  • That looks like c#. Please read my comment (again if necessary). This is the answer to your question. If you have another question, accept this answer and post the relevant code. – James Hill Jul 06 '14 at 14:06