So, when you are working with a Web Forms application it is probably best to stick with the way that it was intended to be used.
Microsoft has made tools available to you, such as the asp.net TextBox control that makes it easier than you think to interact with data in your server code.
The TextBox control is a .net object that exposes properties like the "Text" property so that you can retrieve this information without having to go through the Request object like you would have to do in classic asp or php type environments.
For example, say you have your ASP.NET web form as such:
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head runat="server">
-
<title></title>
-
<style type="text/css">
-
.prompt
-
{
-
display: block;
-
font-weight: bold;
-
}
-
.messageTextArea, .textInput
-
{
-
width: 20em;
-
}
-
.messageTextArea
-
{
-
height: 20em;
-
}
-
</style>
-
</head>
-
<body>
-
<form id="form1" runat="server">
-
<div>
-
<div>
-
<span class="prompt">Please provide your email:</span>
-
<asp:TextBox ID="user_email" runat="server" CssClass="textInput" /></div>
-
<div>
-
<span class="prompt">Please provide your subject:</span>
-
<asp:TextBox ID="user_subject" runat="server" CssClass="textInput" />
-
</div>
-
<div>
-
<span class="prompt">Please provide your message:</span>
-
<asp:TextBox ID="user_message" runat="server" Wrap="true" TextMode="MultiLine" CssClass="messageTextArea" />
-
</div>
-
<asp:Button ID="SendEmail" runat="server" Text="Send Email" />
-
</div>
-
</form>
-
</body>
-
</html>
When ASP.NET sends this to the browser, it is converted into HTML and it looks like this:
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head><title>
-
-
</title>
-
<style type="text/css">
-
.prompt
-
{
-
display: block;
-
font-weight: bold;
-
}
-
.messageTextArea, .textInput
-
{
-
width: 20em;
-
}
-
.messageTextArea
-
{
-
height: 20em;
-
}
-
</style>
-
</head>
-
<body>
-
<form method="post" action="./contact.aspx" id="form1">
-
<div class="aspNetHidden">
-
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUIODY2MjY4OThkZJqkRtnq0NOON5F088ku42vFoM2qk5VPCGYvsOj1lnC3" />
-
</div>
-
-
<div class="aspNetHidden">
-
-
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="CD2448B2" />
-
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAWoASbgPc0NVNHyADJ8kYTN8WW+kaztJcywh7J3De2DyObVknTnR8DQ8XKfcR0YLpUfjPWxNAflCdG320Un8qULhm2+bBR3PLoxYiWNvjlmDhwLAUvc6M1f26OT+paV9sDCllv7rOjBDebf7FFjtYC1" />
-
</div>
-
<div>
-
<div>
-
<span class="prompt">Please provide your email:</span>
-
<input name="user_email" type="text" id="user_email" class="textInput" /></div>
-
<div>
-
<span class="prompt">Please provide your subject:</span>
-
<input name="user_subject" type="text" id="user_subject" class="textInput" />
-
</div>
-
<div>
-
<span class="prompt">Please provide your message:</span>
-
<textarea name="user_message" rows="2" cols="20" id="user_message" class="messageTextArea">
-
</textarea>
-
</div>
-
<input type="submit" name="SendEmail" value="Send Email" id="SendEmail" />
-
</div>
-
</form>
-
</body>
-
</html>
-
ASP.NET automatically converts its objects into HTML for you when it sends the data down to the browser. Likewise, it automatically creates the .NET objects (the button and TextBox objects) and populates them with what the user supplies in the browser when the user submits the form.
So, this would be the VB.NET server code that would retrieve the information from the user based on what the user supplied in the browser:
-
Public Class contact
-
Inherits System.Web.UI.Page
-
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
-
End Sub
-
-
-
Private Sub SendEmail_Click(sender As Object, e As System.EventArgs) Handles SendEmail.Click
-
Dim suppliedEmailText = user_email.Text
-
Dim suppliedSubjectText = user_subject.Text
-
Dim suppliedMessageText = user_message.Text
-
-
-
End Sub
-
End Class
Notice that the
SendEmail
button object has a Click event? That event is created by ASP.NET when the user submits the form by clicking the button. When the button is created, the TextBoxes are also created. After they are initialized, they are populated with data that the user provided in the form in the browser.
After the event is created and the text boxes are populated, the server-side code for the page that handles the Click event is executed to do stuff...like retrieve the information the user provided (validate the information the user provided) and send the email (or not if the data isn't valid).
You should familiarize yourself with the
ASP.NET Page Life Cycle so that you can understand how the process of sending and retrieving data works in Web Forms projects (along with understanding the events that occur in this process too)
For more information on how to send an email using .NET check out this Bytes article:
Quick Reference on how to send an email using .NET
Let me know if you have any questions or problems.
ASP.NET is a pretty big topic!