It’s rather simple in ASP.Net to create a generic FeedBack form. You can make it as simple or as complicated as you need. The simplest form would be merely a Form-To-Email version, which would ONLY send an email of the feedback to a specific destination. In many cases, this would for many users. However, most often, the reality is that sometimes emails get lost. Therefore, it would be more preferable to enter the data from the form, and then, also send the results by email. This way, if the email gets lost, there is still a record of the FeedBack.
There are a couple of things to consider when starting the design process. They are:
- Which database are you going to use?
- How many pieces of Information are you needing to capture?
- How do you want to interact with the data, once it’s in the database?
You can use any you want in this scenario, of course, but we’re only covering SQL Server and MS Access. It really doesn’t matter, in the long run. For most ANSII sql compliant databases, everything is going to be the same, except for the methods used to talk back and forth to the databases.
We also will only cover the basic fields needed in the form, but you can make the form as simple or complex as needed for your own purposes, as stated before. Just remember – for every field you have in the form, you should have a corresponding field in the database table which will be capturing the end-user’s input.
The fields we’ll be covering here are:
- Title
- Email Address (the address of the person entering the feedback,for follow-up)
- Feedback (multi-line textbox, sized as needed)
- Time Entered (automatic)
- Follow-up
You will need to create a database table with these fields – start with an ID field (autonumbering in MS Access or Identity in SQL Server – set as Primary Key also). Then, create the other fields however you’d like, size-wise, making the Time Entered field a Date/Time field and in our case, we’ll make the Follow-up field very small so that a ‘Yes’ can be entered when follow-up is finished concerning the feedback. If you’d like, you can add an extra field for follow-up notes.
Here is how the Form will look on the page:
Title: <asp:TextBox id="txtTitle" Runat="server" /><br>
Email Address: <asp:TextBox id="txtEmail" Runat="server" /><br>
Feedback:<br>
<asp:TextBox id="txtFeedback" Rows="4" Width="500" TextMode="MultiLine" Runat="server" /><p>
<asp:Button id="btnSubmit" Text="Submit" onclick="doInsert" Runat="server" />
As you probably noticed, the last two items in the list (Time Entered and Follow-Up) above are not included in the visual code for the feedback form. That’s because we will automatically get the system date and time and enter it into the database when the data is inserted, and the Follow-Up field is not for input, but obviously, as the name implies, for ‘follow-up’ – AFTER the data has been captured from the form.
Now, next, we’ll need an input sub that takes care of gathering the data entered into the form. Here is the code for doing just that:
Sub doInsert(Source as Object, E as EventArgs)
Dim strConn as String = "server=YourServer;uid=sa;pwd=YourPWD;database=YourDB;"
Dim MySQL as string = "Insert into feedback (Title, Email, Feedback, dtEntered, Followup) " & _
"Values (@Title, @Email, @Feedback, @dtEntered)"
Dim MyConn as New SQLConnection(strConn)
Dim Cmd as New SQLCommand(MySQL, MyConn)
With Cmd.Parameters
.Add(New SQLParameter("@Title", frmTitle.text))
.Add(New SQLParameter("@Title", frmEmail.text))
.Add(New SQLParameter("@Feedback", frmFeedback.text))
.Add(New SQLParameter("@dtEntered", DateTime.Now()))
End With
MyConn.Open()
cmd.ExecuteNonQuery()
'Put your Success statement Here
'Create a label on the page and assign the success statement to the label's text value, like:
'Label1.Text="Your inormation has been successfully received. " & _
"We will get back to you as soon as possible"
'Remember to Import the SQLClient Namespace also
MyConn.Close
End Sub
Continues…