The most important feature of Elanat is its add-ons-oriented structure. Add-ons-oriented structure allows you to create your own Add-ons without conflicting with Eanat core.
CodeBehind Framework Tutorial Series - Send data by submitting form
Send Data by Submitting Form in CodeBehind Framework
In this tutorial, we teach you how to submit form data in the CodeBehind framework. To keep it simple, we just added a View page with a Controller class and didn't use a Model.
View
We created a View page that contains several inputs that are inside the form tag. The form tag uses the post method; in order to upload a file, the enctype attribute is added along with the multipart/form-data value in the form tag.
View page is a form that includes the following inputs:
- TextBox
- Color
- Date
- Time
- Date Time Local
- Week
- Month
- Number
- Email
- Tel
- URL
- Search
- Password
- Range
- Select
- Hidden
- CheckBox
- RadioButton
- File
- Textarea (is use textarea tag name)
- Reset
- Submit
View (myform.aspx)
This is the image of the View screen after execution.
Controller
We added a Controller class and in the PageLoad method we check the presence of data named btn_Button in the form data.
Checking the existence of data with the name btn_Button
According to the above codes, if there is a data named btn_Button, the btn_Button_Click method is called with the context argument.
Clicking on the "Click to send data" button causes the data of the form named btn_Button to be sent to the server.
The HTML tag below shows the btn_Button button
All input tag except radio like text, hidden, select, and radio inputs have text values and their data is retrieved as follows.
Note: The textarea tag value is also retrieved according to the code below.
The InputName value is an example and the name of the input tag should be replased.
Example:
The checkbox input sends a text data with the value on if its tick value is active.
The code below shows how to read checkbox data.
To receive the file, we used the IFormFile data type.
How to get the file is specified in the codes below.
As it is clear in the codes above, first we create a data value of IFormFile type and value it with the input file data.
Then we check whether the input file is initialized on the user side or not. If the initialization is done on the user side, the file will be uploaded.
To check that we have received the data correctly, we add the received data on the page using the WebForms Core technology.
We call the IgnoreAll method; enabling the IgnoreAll method causes the View and Layout to be completely ignored and only the Controller values are added to the page.
The values of the text below are displayed after clicking on the "Click to send data" button.