Tejas February 2016

How to Fire Submit button Click Event using WebRequest

I have the following HTML code and I want to fire the click event of accept submit button using WebRequest in C#

<form method="get" action="test">
          <input class="accept" type="submit" value="Accept">
          <input class="decline" type="button" name="decline" value="Decline">
</form>

Please let me know the ways t0 achieve this.

Thanks.

Answers


Georg Patscheider February 2016

When you click "Accept", the browser will automatically send a GET request to the specified action "test" on the server hosting the webpage that contains the form.

GET http://example.com/test?

Here is an example to illustrate that "firing the sumbit event" has nothing to do with C#, but is a feature of html.

Let`s put your form into a simple html page and save it as form.html somewhere on your computer:

<html>
    <body>
        <form method="get" action="accepted.html">
            <input class="accept" type="submit" value="Accept">
            <input class="decline" type="button" name="decline" value="Decline">
        </form>
    </body>
</html>

Note that the action now goes to "accepted.html". Put another html file called "accepted.html" into the same folder as form.html. When you open form.html in your browser and click "Accept", the static page accepted.html will be shown. (Here your webbrowser also acts as server for local files.)

So your question is probably not "How do I fire the click event of the submit button" but rather "How do I handle dynamic requests instead of serving static pages".

You want your webserver to intercept the request for the GET action 'test', run some C# to process it and show the results. A good framework to do this is ASP.Net MVC.

Post Status

Asked in February 2016
Viewed 1,922 times
Voted 8
Answered 1 times

Search




Leave an answer