title: Why are these asp values not passed to code behind? (ASP & Visual Studio)
body: <p>This web form should feed into an access database. 
  However it keeps saying stuff like " Field 'Exhibits.FirsNtame' cannot be a zero-length string." I know the code works because it will write to the database if I hard code in values. How do I get values to the variables in the code behind the page?</p>
  
  <p>Here is the web page:</p>
  
  <pre><code>      &lt;%@ Page Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="ScienceFair.aspx.vb" Inherits="_Default" %&gt;
  
      &lt;asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server"&gt;
  
  
          &lt;style type="text/css"&gt;
              .auto-style1 {
                  text-align: center;
              }
          &lt;/style&gt;
  
  
      &lt;/asp:Content&gt;
      &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server"&gt;
          &lt;div id="RuleBreaker"&gt;
          &lt;h2 class="auto-style1"&gt;Science Fair Registration&lt;/h2&gt;
          &lt;p class="auto-style1" &gt;
              First Name:
              &lt;br /&gt;
              &lt;asp:TextBox ID="FirsNtame" runat="server" AutoCompleteType="FirstName"&gt;&lt;/asp:TextBox&gt;
              &lt;br /&gt;
  
      &lt;asp:RequiredFieldValidator id="FirsNtameValidator1" runat="server"
        ControlToValidate="FirsNtame"
        ErrorMessage="A first name is required."
        ForeColor="Red"&gt;
      &lt;/asp:RequiredFieldValidator&gt;
              &lt;br /&gt;
  
              Last Name:
              &lt;br /&gt;
              &lt;asp:TextBox ID="LasNtame" runat="server" AutoCompleteType="LastName"&gt;&lt;/asp:TextBox&gt;
              &lt;br /&gt;
  
      &lt;asp:RequiredFieldValidator id="LasNtameValidator2" runat="server"
        ControlToValidate="LasNtame"
        ErrorMessage="A last name is required."
        ForeColor="Red"&gt;
      &lt;/asp:RequiredFieldValidator&gt;
              &lt;br /&gt;
  
              Student Email Address:
              &lt;br /&gt;
              &lt;asp:TextBox ID="StudentEmail" runat="server" AutoCompleteType="Email"&gt;&lt;/asp:TextBox&gt;
              &lt;br /&gt;
  
      &lt;asp:RequiredFieldValidator id="StudentEmailValidator3" runat="server"
        ControlToValidate="StudentEmail"
        ErrorMessage="A Student Email is required."
        ForeColor="Red"&gt;
      &lt;/asp:RequiredFieldValidator&gt;
  
               &lt;br /&gt;
               &lt;br /&gt;
              School:
               &lt;br /&gt;
              &lt;asp:TextBox ID="School" runat="server"&gt;&lt;/asp:TextBox&gt;
              &lt;br /&gt;
  
      &lt;asp:RequiredFieldValidator id="SchoolValidator4" runat="server"
        ControlToValidate="School"
        ErrorMessage="Your school name is required."
        ForeColor="Red"&gt;
      &lt;/asp:RequiredFieldValidator&gt;
  
               &lt;br /&gt;
              Grade:
              &lt;br /&gt;
                  &lt;asp:DropDownList id="Grade" runat="server" Width="86px"&gt;
                      &lt;asp:ListItem&gt;7&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;8&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;9&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;10&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;11&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;12&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;
              &lt;br /&gt;
  
      &lt;asp:RequiredFieldValidator id="GradeValidator5" runat="server"
        ControlToValidate="Grade"
        ErrorMessage="A grade is required."
        ForeColor="Red"&gt;
      &lt;/asp:RequiredFieldValidator&gt;
  
              &lt;br /&gt;
                  Teacher's Last Name (only):&lt;br /&gt;
                  &lt;asp:TextBox id="Teacher" runat="server" Width="500px"&gt;&lt;/asp:TextBox&gt;
                  &lt;br /&gt;
  
      &lt;asp:RequiredFieldValidator id="TeacherValidator6" runat="server"
        ControlToValidate="Teacher"
        ErrorMessage="A teacher last name is required."
        ForeColor="Red"&gt;
      &lt;/asp:RequiredFieldValidator&gt;
              &lt;br /&gt;
  
                  Teacher E-mail:&lt;br /&gt;&amp;nbsp;&lt;asp:TextBox ID="TeacherEmail" runat="server" 
                      Width="500px"&gt;&lt;/asp:TextBox&gt;
                  &lt;br /&gt; 
  
      &lt;asp:RequiredFieldValidator id="TeacherEmailValidator7" runat="server"
        ControlToValidate="TeacherEmail"
        ErrorMessage="A teacher email is required field."
        ForeColor="Red"&gt;
      &lt;/asp:RequiredFieldValidator&gt;
              &lt;br /&gt;
  
                  &lt;%-- Teacher Phone Number:&lt;br /&gt;&amp;nbsp;&lt;asp:TextBox id="TPhone" runat="server" Width="500px"&gt;&lt;/asp:TextBox&gt; --%&gt;
                  &lt;%-- Might put the above in later --%&gt;
                  Catagory :&lt;br /&gt;&amp;nbsp;&lt;asp:DropDownList id="Catagory" runat="server" Width="212px"&gt;
                      &lt;asp:ListItem&gt;Behavorial &amp;amp; Social Sciences&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Biochemistry &amp;amp; Microbiology&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Botany&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Environmental Sciences&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Medicine &amp;amp; Health&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Zoology&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Chemistry&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Computer Science&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Earth &amp;amp; Space Sciences&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Engineering&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Mathematics&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Physics&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;
                  &lt;br /&gt;
  
      &lt;asp:RequiredFieldValidator id="CatagoryValidator8" runat="server"
        ControlToValidate="Catagory"
        ErrorMessage="A catagory is required."
        ForeColor="Red"&gt;
      &lt;/asp:RequiredFieldValidator&gt;
              &lt;br /&gt;
  
                  Exibit Title :&lt;br /&gt;&amp;nbsp;&lt;asp:TextBox id="ExibitTite" runat="server" Width="500px"&gt;&lt;/asp:TextBox&gt;
                  &lt;br /&gt;
  
      &lt;asp:RequiredFieldValidator id="ExibitTiteValidator9" runat="server"
        ControlToValidate="ExibitTite"
        ErrorMessage="A title is required."
        ForeColor="Red"&gt;
      &lt;/asp:RequiredFieldValidator&gt;
              &lt;br /&gt;
  
                  Does your exhibit use electricity?&lt;br /&gt;
                  &lt;%-- Possible issues here, may need to use 1 &amp; 0 instead--%&gt;
                  &lt;asp:DropDownList id="Electricity" runat="server"&gt;
                      &lt;asp:ListItem Value="Yes"&gt;Yes&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Value="No"&gt;No&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;
              &lt;br /&gt;
  
       &lt;asp:RequiredFieldValidator id="ElectricityValidator10" runat="server"
        ControlToValidate="Electricity"
        ErrorMessage="Does your computer use electricity?"
        ForeColor="Red"&gt;
      &lt;/asp:RequiredFieldValidator&gt;
              &lt;br /&gt;
  
          &lt;/p&gt;
              &lt;p class="auto-style1" &gt;
                  &lt;asp:Button ID="SciFairSubmit" runat="server" Text="Submit" /&gt;
                  &lt;br /&gt;
                  &lt;br /&gt;
          &lt;/p&gt;
          &lt;/div&gt;
  
      &lt;/asp:Content&gt;
  </code></pre>
  
  <p>Here is the aspx code behind the page:</p>
  
  <pre><code> Imports System.Data.OleDb
  
      Partial Class _Default
          Inherits System.Web.UI.Page
  
          Protected Sub SciFairSubmit_Click(sender As Object, e As EventArgs) Handles SciFairSubmit.Click
              'form data requests----------------------------------------------------------------------------C:\Users\NCG-PC\Webmastering\TamugSciFair13\WebSite1\Default1.aspx.vb
  
              Dim strName As String = If(Request.Form("FirsNtame"), "")
              Dim strLasNtame As String = If(Request.Form("LasNtame"), "")
              Dim strStudentEmail As String = If(Request.Form("strStudentEmail"), "")
  
              Dim strSchool As String = If(Request.Form("strSchool"), "")
              Dim numGrade As String = If(Request.Form("numGrade"), "")
              Dim strTeacher As String = If(Request.Form("strTeacher"), "")
              Dim strTeacherEmail As String = If(Request.Form("strTeacherEmail"), "")
  
              Dim strCatagory As String = If(Request.Form("strCatagory"), "")
              Dim strExibitTite As String = If(Request.Form("strExibitTite"), "")
              Dim strElectricity As String = If(Request.Form("strElectricity"), "")
  
              'Open Db Connection---------------------------------------------------------------------------------------------------------
              Dim strSQL As String
              Dim dbconn As OleDbConnection = Nothing
  
              dbconn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;data source=" &amp; Server.MapPath("\GalvestonScienceFair\App_Data\sf13.mdb"))
              dbconn.Open()
  
              'SQL actions ----------------------------------------------------------------------------------------------------------
              strSQL = "INSERT INTO Exhibits (FirsNtame, LasNtame, StudentEmail, School, Grade, Teacher, TeacherEmail, Category, ExibitTite, Electricity) values (@FirsNtame, @LasNtame, @StudentEmail, @School, @Grade, @Teacher, @TeacherEmail, @Category, @ExibitTite, @Electricity)"
              Dim objcmd = New OleDbCommand(strSQL, dbconn)
  
  
  
  
              objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@FirsNtame", strName))
              objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@LasNtame", strLasNtame))
              objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@StudentEmail", strStudentEmail))
  
              objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@School", strSchool))
              objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Grade", numGrade))
              objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Teacher", strTeacher))
              objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@TeacherEmail", strTeacherEmail))
  
              objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Category", strCatagory))
              objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@ExibitTite", strExibitTite))
              objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Electricity", strElectricity))
  
              'Sets each parameter to "DBNULL" or "blank" if they are null/blank
              'objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@FirsNtame", If(strName, DBNull.Value)))
              For Each param As System.Data.OleDb.OleDbParameter In objcmd.Parameters
                  If param.Value Is Nothing Then
                      param.Value = DBNull.Value
                  End If
              Next
  
              objcmd.ExecuteNonQuery()
              'Close DB Connection
              dbconn.Close()
              Response.Write("Thank you for registering!")
          End Sub
      End Class
  </code></pre>