How do I get the values when submitting a form (either using GET or POST)?

How do I get the values when submitting a form (either using GET or POST)?

This is a popular question among ASP.NET beginners, because this is done fairly different with .NET. While in PHP you would use $HTTP_POST_VARS[‘field1’] and $HTTP_GET_VARS[‘field1’] to get the value passed from a form (either using POST or GET method), in ASP.NET there is a big difference.
First, if you pass the value using the GET method (passed as parameters in the URL), you can retrieve those values similar to how you would done it in PHP:


However, when submitting large forms or forms containing sensitive information such as passwords, you will want to use the POST method. Retrieving values passed by using the POST method is nothing like retrieving them using the GET method – you simply access the form elements like you would in any Windows application. Remember, for this to work you need to use .NET controls such as TextBox and Button, and not HTML controls.

// If the form was submitted
string FName = txtFName.Text;

As you can see in the above example, to get a value of an element in a submitted form, you simply access that element’s property. But you first check if IsPostBack is true – if the form was submitted.

Nathan Pakovskie is an esteemed senior developer and educator in the tech community, best known for his contributions to With a passion for coding and a knack for simplifying complex tech concepts, Nathan has authored several popular tutorials on C# programming, ranging from basic operations to advanced coding techniques. His articles, often characterized by clarity and precision, serve as invaluable resources for both novice and experienced programmers. Beyond his technical expertise, Nathan is an advocate for continuous learning and enjoys exploring emerging technologies in AI and software development. When he’s not coding or writing, Nathan engages in mentoring upcoming developers, emphasizing the importance of both technical skills and creative problem-solving in the ever-evolving world of technology. Specialties: C# Programming, Technical Writing, Software Development, AI Technologies, Educational Outreach

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top