How to Input a Value & Return a Value on a Web Page
One common aspect of a Web page is a form that retrieves user input values and displays these values after the website visitor clicks a "Submit" button. Using C#, you can create a Web form and return values for display on the next Web page. C# is a part of the .NET framework, and values are manipulated and used in a section of the Web form called the "code behind." In the code behind file, you can return the value after the user has submitted form values.
Instructions
-
Instructions
-
1
Open Visual Studio and load your website project. Right-click the website name in Solution Explorer and select "New" then "Web Form." This creates a new Web page to test the form values.
-
2
Drag and drop the "Textbox" object in the toolbox located on the left of the screen. This creates a Web form textbox object where users can input text into the Web page. In the properties window underneath Solution Explorer, name the new text box "My_TextEntry" and press the "Enter" key. This is the name you will use to retrieve your user input and display it on the page.
-
-
3
Drag and drop a "Button" component from the toolbox to the Web page. This creates a button that the user clicks to submit the information.
-
4
Right-click the Web form and select "View Code." This opens the code behind the file used to program functions that manipulate data. The function that opens by default is the "Page_Load" event. This event is run each time the Web page is loaded, including when the user refreshes or presses a "Submit" button.
-
5
Type the following code into the Page_Load function:
Response.Write(My_TextEntry.Text);
This code prints the user's input to the Web page. -
6
Save the page. Right-click the Web form in Solution Explorer and select "View in Browser." This opens the page in a Web browser. Enter "my first web form" into the text box and click the "Submit" button. The text is retrieved and returned to the Web page.
-
1