-3

I want to fill a textbox in a website and click the submit button using C#

How can I do it ?

Html textbox code:

<input id="url" class="span8" type="text" placeholder="http://" name="url"></input>

Html button code:

<button id="preview" class="btn btn-large btn-primary" name="preview" type="submit" value="1"><i class="icon-eye-open icon-white"></i> Upload</button>
M.Tajari
  • 59
  • 11
  • 3
    What are you doing this from? A desktop application (WPF, Console, or Win Forms) or ASP.NET (MVC or Web Forms). Please realize that you must give more detail because we are not familiar with your application. – mason Apr 16 '14 at 14:10
  • You can't click a html input box using C#, unless you are talking about a web driver framework like Selenium? You'll have to expand your question a bit I'm afraid. – samjudson Apr 16 '14 at 14:11
  • 1
    @samjudson He needs more detail here, I doubt he's talking about automating the click of a button, I'd guess he's talking about the user clicking the button. – Ciaran Gallagher Apr 16 '14 at 14:13
  • @mason I using Windows form and just want to fill a textbox in this address : http://www.newocr.com/ and submit it – M.Tajari Apr 16 '14 at 14:20
  • @samjudson As I said I want only fill the the URL textbox in this address : http://www.newocr.com/ and submit the form using C# – M.Tajari Apr 16 '14 at 14:21
  • I don't think a windows form will support html tags. Are you using Web Forms? – bsayegh Apr 16 '14 at 14:28
  • You'll want to POST data to the server, rather than actually filling out the form. See [How To Send Data Using the WebRequest Class](http://msdn.microsoft.com/en-us/library/debx8sh9(v=vs.110).aspx) on MSDN. – mason Apr 16 '14 at 14:32
  • This question appears to be a duplicate of [Post to remote URL, read response](http://stackoverflow.com/questions/23114607/post-to-remote-url-read-response). I particularly like the answer on that was that wasn't accepted. – mason Apr 16 '14 at 17:07

1 Answers1

0

Try putting the

runat="server"

in your input, and see if you can call it in the codebehind. If this doesn't work change it by some control that C# can understand.

Anyway, your button should look like this:

<asp:Button runat="server" ID="Save" CssClass="someCSSClass" Text="Save" />
Flavio Santini
  • 101
  • 1
  • 4
  • He's not using ASP.NET. It's a Windows Forms application, the form appears to reside on a server and he wants to programmatically submit it. – mason Apr 16 '14 at 14:30