title: ASP.NET VB Page_Load Only Once or Alternative
body: <p>I'm a little stuck on what to do! I have a special form that allows my customers to request a quote for a specific product (defined by PID in url) The form is loaded inside a modal dialogue and within that a Iframe. The Iframe's src value is set from the onclick event of ahref on the product pages eg;</p>
  
  <pre><code>&lt;div id='basic-modal'&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href='#' class='basic' onClick="document.getElementById('ifr').src='quote/Public/Default.aspx?PID=111'"&gt;CLICK ME&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;
  
      &lt;div id="basic-modal-content"&gt;
          &lt;iframe id="ifr" width="850px" height="600px" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;
  </code></pre>
  
  <p></p>
  
  <p>The form that I am loading does a SQL insert when Page_Load is fired. Also it is within 
      If Page.IsPostBack = False Then</p>
  
  <p>For some strange reason the page is doing it twice when the page loads and another time when the page is closed.. I need the SQL insert on the first page load as the returned values are used by my form. Can anyone suggest a good way of making the code within Page_Load only fire up once?</p>
  
  <p>Many thanks!</p>
  
  <p>UPDATE, Full Code:</p>
  
  <p>aspx page</p>
  
  <pre><code>&lt;%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Public_Default" %&gt;
  &lt;%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
  &lt;link href="../quoteFront.css" rel="stylesheet" type="text/css" /&gt;
  &lt;title&gt;&lt;/title&gt;    
  &lt;style type="text/css"&gt;
      .style1
      {
          width: 100%;
      }
      .style2
      {
          height: 26px;
      }
      .style5
      {
          width: 299px;
      }
      .style6
      {
          width: 174px;
      }
      .style7
      {
          height: 26px;
          width: 174px;
      }
      .style8
      {
          width: 291px;
      }
      .style9
      {
          height: 26px;
          width: 189px;
      }
      .style10
      {
      }
      .style11
      {
          width: 189px;
      }
      .style12
      {
          width: 191px;
      }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form id="form1" runat="server"&gt;
  &lt;div&gt;
      &lt;cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePartialRendering="true" CombineScripts="false"  &gt;
      &lt;/cc1:ToolkitScriptManager&gt;
  &lt;/div&gt;
  &lt;asp:UpdatePanel ID="UpdatePanel3" runat="server"&gt;&lt;ContentTemplate&gt;
  &lt;asp:Panel ID="Panel2" runat="server"&gt;    
  &lt;table class="style1"&gt;
      &lt;tr&gt;
          &lt;td class="style12"&gt;
              First name&lt;/td&gt;
          &lt;td class="style5"&gt;
              &lt;asp:TextBox ID="txtFirstName" runat="server" Width="300px" 
                  AutoCompleteType="FirstName"&gt;&lt;/asp:TextBox&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                  ControlToValidate="txtFirstName" ErrorMessage="* Required" ForeColor="Red"&gt;&lt;/asp:RequiredFieldValidator&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td class="style12"&gt;
              Last name&lt;/td&gt;
          &lt;td class="style5"&gt;
              &lt;asp:TextBox ID="txtLastName" runat="server" Width="300px" 
                  AutoCompleteType="LastName"&gt;&lt;/asp:TextBox&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                  ControlToValidate="txtLastName" ErrorMessage="* Required" ForeColor="Red"&gt;&lt;/asp:RequiredFieldValidator&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td class="style12"&gt;
              Company name&lt;/td&gt;
          &lt;td class="style5"&gt;
              &lt;asp:TextBox ID="txtCompanyName" runat="server" Width="300px" 
                  AutoCompleteType="Company"&gt;&lt;/asp:TextBox&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &amp;nbsp;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td class="style12"&gt;
              Email address&lt;/td&gt;
          &lt;td class="style5"&gt;
              &lt;asp:TextBox ID="txtEmailAddress" runat="server" Width="300px" AutoCompleteType="Email"&gt;&lt;/asp:TextBox&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                  ControlToValidate="txtEmailAddress" ErrorMessage="* Required" 
                  ForeColor="Red"&gt;&lt;/asp:RequiredFieldValidator&gt;
  &lt;asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                  ControlToValidate="txtEmailAddress" ErrorMessage=" * Invalid email address" 
                  ForeColor="Red" 
                  ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"&gt;&lt;/asp:RegularExpressionValidator&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td class="style12"&gt;
              Phone number&lt;/td&gt;
          &lt;td class="style5"&gt;
              &lt;asp:TextBox ID="txtPhoneNumber" runat="server" Width="300px" AutoCompleteType="BusinessPhone"&gt;&lt;/asp:TextBox&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" 
                  ControlToValidate="txtPhoneNumber" ErrorMessage="* Required" 
                  ForeColor="Red"&gt;&lt;/asp:RequiredFieldValidator&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;asp:UpdatePanel ID="UpdatePanel2" runat="server"&gt;
  &lt;ContentTemplate&gt;
  &lt;div&gt;
          &lt;table class="style1"&gt;
          &lt;tr&gt;
              &lt;td class="style11"&gt;
                  Quantity required&lt;/td&gt;
              &lt;td class="style6"&gt;
                  &lt;asp:TextBox ID="txtQuantity1" runat="server" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;
                  &lt;cc1:FilteredTextBoxExtender ID="ftbe" runat="server" FilterType="Numbers" 
                      TargetControlID="txtQuantity1" /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" 
                      ControlToValidate="txtQuantity1" 
                      ErrorMessage="* Please enter quantity required" ForeColor="Red"&gt;&lt;/asp:RequiredFieldValidator&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class="style11"&gt;
                  &lt;asp:Label ID="lblDesigninfo" runat="server" Text="Printing info"&gt;&lt;/asp:Label&gt;
              &lt;/td&gt;
              &lt;td class="style6"&gt;
                  &lt;asp:DropDownList ID="drpDesignInfo1" runat="server" AutoPostBack="True" 
                      DataSourceID="SqlDataSource1" DataTextField="PrintInfoDesc" 
                      DataValueField="ID" AppendDataBoundItems="True"&gt;
                      &lt;asp:ListItem&gt;&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;
                  &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                      ConnectionString="&lt;%$ ConnectionStrings:quotingSystemConnectionString %&gt;" 
                      SelectCommand="SELECT [ID], [PrintInfoDesc] FROM [PrintInfo]"&gt;
                  &lt;/asp:SqlDataSource&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" 
                      ControlToValidate="drpDesignInfo1" ErrorMessage="* Please select" 
                      ForeColor="Red"&gt;&lt;/asp:RequiredFieldValidator&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class="style11"&gt;
                  &lt;asp:Label ID="lblColoursSideOne1" runat="server" 
                      Text="Colour options first side" Visible="True"&gt;&lt;/asp:Label&gt;
              &lt;/td&gt;
              &lt;td class="style6"&gt;
                  &lt;asp:DropDownList ID="drpColoursSideOne1" runat="server" Visible="True" 
                      AutoPostBack="True"&gt;
                  &lt;/asp:DropDownList&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &amp;nbsp;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class="style9"&gt;
                  &lt;asp:Label ID="lblColoursSideTwo1" runat="server" 
                      Text="Colour options second side" Visible="false"&gt;&lt;/asp:Label&gt;
              &lt;/td&gt;
              &lt;td class="style7"&gt;
                  &lt;asp:DropDownList ID="drpColoursSideTwo1" runat="server" Visible="false"&gt;
                  &lt;/asp:DropDownList&gt;
              &lt;/td&gt;
              &lt;td class="style2"&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  &lt;/ContentTemplate&gt;
      &lt;Triggers&gt;
      &lt;asp:AsyncPostBackTrigger ControlID="txtQuantity1" EventName="TextChanged" /&gt;
      &lt;asp:AsyncPostBackTrigger ControlID="drpDesignInfo1" 
          EventName="SelectedIndexChanged" /&gt;
      &lt;asp:AsyncPostBackTrigger ControlID="drpColoursSideOne1" 
          EventName="SelectedIndexChanged" /&gt;
  &lt;/Triggers&gt;
  &lt;/asp:UpdatePanel&gt;
  &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;&lt;ContentTemplate&gt;
  &lt;div style="text-align: center"&gt;Please fill in the above fields before uploading 
  artwork.
  &lt;br /&gt;
  When the upload is complete you will get the option to upload additional 
  artwork.
                  &lt;cc1:AsyncFileUpload ID="AsyncFileUpload1" runat="server" 
                      CompleteBackColor="Lime" ErrorBackColor="Red" 
                      OnClientUploadComplete="UploadComplete" OnClientUploadError="uploadError" 
                      OnClientUploadStarted="StartUpload" 
                      onuploadedcomplete="AsyncFileUpload1_UploadedComplete" ThrobberID="Throbber" 
                      UploaderStyle="Modern" UploadingBackColor="#66CCFF" Width="100%" 
                      ClientIDMode="Inherit" /&gt;
                                      &lt;asp:Label ID="Throbber" runat="server" Style="display: none"&gt;
  &lt;img src="../Images/indicator.gif" align="absmiddle" alt="loading" /&gt;
  &lt;/asp:Label&gt;&lt;asp:Label ID="lblStatus" runat="server"&gt;&lt;/asp:Label&gt;
                  &lt;br /&gt;
  &lt;div style="max-height:70px; overflow : auto; "&gt;
                  &lt;asp:Label ID="lblUploadList" runat="server" ForeColor="#006600" 
                      Font-Size="Smaller"&gt;&lt;/asp:Label&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;        
  &lt;table class="style1"&gt;
          &lt;tr&gt;
              &lt;td class="style10"&gt;
                  Any aditional info&lt;asp:TextBox ID="txtComments" runat="server" Height="111px" 
                      TextMode="MultiLine" Width="100%"&gt;&lt;/asp:TextBox&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class="style8"&gt;
                  &lt;asp:Button ID="Button1" runat="server" Text="Send Request" Width="100%" 
                      Height="45px" Font-Bold="False" /&gt;
              &lt;/td&gt;
  
          &lt;/tr&gt;
      &lt;/table&gt;
  
  &lt;/asp:Panel&gt;
       &lt;br /&gt;
  &lt;asp:Panel ID="Panel1" runat="server" Visible="False"&gt;
      Thank you for requesting a quote. A member of our sales team will be in touch 
      shortly.&lt;br /&gt;
      &lt;br /&gt;
      &lt;asp:Button ID="btnRequestAnother" runat="server" 
          Text="Request another quote for this product" CausesValidation="False" 
          Height="45px" Width="100%"/&gt;
  &lt;/asp:Panel&gt;
  &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
      &lt;script type="text/javascript" language="javascript"&gt;
  
          function uploadError(sender, args) {
              document.getElementById("lblStatus").innerHTML = "Failed to upload " + args.get_fileName() + ". Please try again. If problem persistes please email sales@thecleverbaggers.co.uk";
              document.getElementById("Button1").innerHTML = 'Send Request';
          }
  
          function StartUpload(sender, args) {
              document.getElementById("lblStatus").innerHTML = 'Uploading Started. Depending on your connection speed this can take a very long time. Please wait....';
              document.getElementById("Button1").innerHTML = 'Uploading Started. Please Wait....';
          }
  
          function UploadComplete(sender, args) {
              var filename = args.get_fileName();
              var contentType = args.get_contentType();
              var text = "Upload Complete, Press Select File to upload more. " //"Size of " + filename + " is " + args.get_length() + " bytes";
              if (contentType.length &gt; 0) {
                  text //+= " and content type is '" + contentType + "'.";
              }
              document.getElementById("lblStatus").innerHTML = text;
              document.getElementById("lblUploadList").innerHTML = document.getElementById("lblUploadList").innerHTML + "&lt;br /&gt;" + filename + " Uploaded Successfully";
              document.getElementById("Button1").innerHTML = 'Send Request';
          }
  
  &lt;/script&gt;
  
  
      &lt;/form&gt;
  
  
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>VB CODE:</p>
  
  <pre><code>Imports System.Data
  Imports System.IO
  Imports System.Data.SqlClient
  
  Partial Class Public_Default
  Inherits System.Web.UI.Page
  Dim ArtworkID As Integer
  Dim customerIDDecrypt As String
  Public QuoteID As Integer
  Dim UploadedFileList As String
  Dim productID As String
  'Shared IsFirstTime As Boolean = False
  
  
  Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
  
      productID = Request.QueryString("PID")
      customerIDDecrypt = "0"
  
      'If Not Page.IsPostBack AndAlso Not IsFirstTime Then
  If Not Page.IsPostBack Then
          Try
              Dim sql As String = "INSERT INTO [Quote] (Status, CreationDate, CreationTime, CustomerID, ProductID, IP)" &amp; _
                  "VALUES (@Status, @CreationDate, @CreationTime, @CustomerID, @ProductID, @IP) SELECT SCOPE_IDENTITY()"
  
              Using cn As New SqlConnection(ConfigurationManager.AppSettings("quotingSystemConnectionString")), _
                    cmd As New SqlCommand(sql, cn)
  
                  cmd.Parameters.Add("@Status", SqlDbType.NVarChar).Value = 1
                  cmd.Parameters.Add("@CreationDate", SqlDbType.Date).Value = Date.UtcNow.ToLocalTime
                  cmd.Parameters.Add("@CreationTime", SqlDbType.Time).Value = Date.UtcNow.ToLocalTime.TimeOfDay
                  cmd.Parameters.Add("@CustomerID", SqlDbType.Int).Value = customerIDDecrypt
                  cmd.Parameters.Add("@ProductID", SqlDbType.Int).Value = productID
                  cmd.Parameters.Add("@IP", SqlDbType.NVarChar).Value = CStr(Request.UserHostAddress())
                  cn.Open()
                  '//grab the ID of this insert.
                  QuoteID = Integer.Parse(cmd.ExecuteScalar().ToString())
  
                  cn.Close()
                  'IsFirstTime = True
              End Using
          Catch ex As Exception
              '// do something with this error!
              Response.Write(ex.Message)
          End Try
      End If
  End Sub
  
  Protected Sub txtQuantity1_TextChanged(sender As Object, e As System.EventArgs) Handles txtQuantity1.TextChanged
      '//populate colours dependant on quantity
      If txtQuantity1.Text &gt; "" Then
          If txtQuantity1.Text &lt; "100" Then
              'side one
              drpColoursSideOne1.Items.Clear()
              'drpColoursSideOne1.Enabled = True
              drpColoursSideOne1.Items.Add(New ListItem("One colour", "1"))
              drpColoursSideOne1.Items.Add(New ListItem("More than one colour", "full"))
              drpColoursSideOne1.Items.Add(New ListItem("I don't know!", "help"))
              drpColoursSideOne1.Visible = True
              'side two
              drpColoursSideTwo1.Items.Clear()
              'drpColoursSideTwo1.Enabled = True
              drpColoursSideTwo1.Items.Add(New ListItem("One colour", "1"))
              drpColoursSideTwo1.Items.Add(New ListItem("More than one colour", "full"))
              drpColoursSideTwo1.Items.Add(New ListItem("I don't know!", "help"))
              drpColoursSideTwo1.Items.Add(New ListItem("na", "na"))
          Else
              'side one
              drpColoursSideOne1.Items.Clear()
              'drpColoursSideOne1.Enabled = True
              drpColoursSideOne1.Items.Add(New ListItem("One colour", "1"))
              drpColoursSideOne1.Items.Add(New ListItem("Two colours", "2"))
              drpColoursSideOne1.Items.Add(New ListItem("Three colours", "3"))
              drpColoursSideOne1.Items.Add(New ListItem("Four colours", "4"))
              drpColoursSideOne1.Items.Add(New ListItem("Five colours", "5"))
              drpColoursSideOne1.Items.Add(New ListItem("Full colour (eg, photo)", "full"))
              drpColoursSideOne1.Items.Add(New ListItem("I don't know!", "help"))
              'side two
              drpColoursSideTwo1.Items.Clear()
              'drpColoursSideTwo1.Enabled = True
              drpColoursSideTwo1.Items.Add(New ListItem("One colour", "1"))
              drpColoursSideTwo1.Items.Add(New ListItem("Two colours", "2"))
              drpColoursSideTwo1.Items.Add(New ListItem("Three colours", "3"))
              drpColoursSideTwo1.Items.Add(New ListItem("Four colours", "4"))
              drpColoursSideTwo1.Items.Add(New ListItem("Five colours", "5"))
              drpColoursSideTwo1.Items.Add(New ListItem("Full colour (eg, photo)", "full"))
              drpColoursSideTwo1.Items.Add(New ListItem("I don't know!", "help"))
              drpColoursSideTwo1.Items.Add(New ListItem("na", "na"))
          End If
      Else
          'nothing
      End If
  End Sub
  
  Protected Sub drpDesignInfo1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles drpDesignInfo1.SelectedIndexChanged
      If drpDesignInfo1.SelectedValue = "1" And txtQuantity1.Text &gt; "0" Then
          lblColoursSideTwo1.Visible = False
          lblColoursSideOne1.Visible = True
          drpColoursSideOne1.Visible = True
          drpColoursSideOne1.Enabled = True
          drpColoursSideTwo1.Visible = False
          drpColoursSideTwo1.Enabled = False
          drpColoursSideTwo1.SelectedValue = "na"
          ' drpColoursSideTwo1.Items.Remove(New ListItem("Same as the first side", "same"))
      ElseIf drpDesignInfo1.SelectedValue = "3" And txtQuantity1.Text &gt; "0" Then
          lblColoursSideOne1.Visible = True
          drpColoursSideOne1.Visible = True
          drpColoursSideOne1.Enabled = True
          lblColoursSideTwo1.Visible = True
          drpColoursSideTwo1.Visible = True
          drpColoursSideTwo1.Enabled = True
          ' drpColoursSideTwo1.Items.Remove(New ListItem("Same as the first side", "same"))
      ElseIf drpDesignInfo1.SelectedValue = "2" And txtQuantity1.Text &gt; "0" Then
          lblColoursSideOne1.Visible = True
          drpColoursSideOne1.Visible = True
          drpColoursSideOne1.Enabled = True
          lblColoursSideTwo1.Visible = True
          drpColoursSideTwo1.Visible = True
          drpColoursSideTwo1.Enabled = False
          ' Dim tmpCount2 = drpColoursSideTwo1.Items.Count
          ' If tmpCount2 = 7 Or tmpCount2 = 3 Then
          'drpColoursSideTwo1.Items.Add(New ListItem("Same as the first side", "same"))
          'End If
          drpColoursSideTwo1.SelectedValue = drpColoursSideOne1.SelectedValue
      End If
  End Sub
  Protected Sub AsyncFileUpload1_UploadedComplete(sender As Object, e As AjaxControlToolkit.AsyncFileUploadEventArgs)
      System.Threading.Thread.Sleep(3000)
      If AsyncFileUpload1.HasFile Then
          'Dim strPath As String = newPath + Path.GetFileName(e.FileName)
          'AsyncFileUpload1.SaveAs(strPath)
  
          Dim fileName = Path.GetFileName(e.FileName)
          'Dim imageBytes(AsyncFileUpload1.PostedFile.InputStream.Length) As Byte
          'AsyncFileUpload1.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.length)
          Dim imageBytes = AsyncFileUpload1.FileBytes
          'AsyncFileUpload1.FileBytes
          '// now insert this into the database
          Try
              Dim sql As String = "INSERT INTO [UploadedFiles] (CustomerID, FileName, FileSize, FileContent, FileType, FileUploadDate, QuoteID)" &amp; _
                  "VALUES (@CustomerID, @FileName, @FileSize, @FileContent, @FileType, @FileUploadDate, @QuoteID) SELECT SCOPE_IDENTITY()"
  
              Using cn As New SqlConnection(ConfigurationManager.AppSettings("quotingSystemConnectionStringLargeTimeout")), _
                    cmd As New SqlCommand(sql, cn)
                  cmd.CommandTimeout = "3600"
  
                  cmd.Parameters.Add("@CustomerID", SqlDbType.Int).Value = 1
                  cmd.Parameters.Add("@FileName", SqlDbType.NVarChar).Value = fileName
                  cmd.Parameters.Add("@FileSize", SqlDbType.NVarChar).Value = AsyncFileUpload1.PostedFile.ContentLength
                  cmd.Parameters.Add("@FileContent", SqlDbType.VarBinary).Value = imageBytes
                  cmd.Parameters.Add("@FileType", SqlDbType.NVarChar, 50).Value = AsyncFileUpload1.PostedFile.ContentType
                  cmd.Parameters.Add("@FileUploadDate", SqlDbType.Date).Value = Date.UtcNow.ToLocalTime
                  cmd.Parameters.Add("@QuoteID", SqlDbType.Int).Value = QuoteID
  
                  cn.Open()
                  '//grab the ID of this insert.
                  ArtworkID = Integer.Parse(cmd.ExecuteScalar().ToString())
                  cn.Close()
              End Using
          Catch ex As Exception
              '// do something with this error!
              Response.Write(ex.Message)
          End Try
      End If
  End Sub
  
  Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
      '// Populate the database with remaining information
      Button1.Text = "Please Wait...  Sending Request"
      Dim thisConnection As New SqlConnection(ConfigurationManager.AppSettings("quotingSystemConnectionString"))
      'Create Command object
      Dim nonqueryCommand As SqlCommand = thisConnection.CreateCommand()
      Try
          ' Open Connection
          thisConnection.Open()
          ' 1. Create Command
          ' Sql Update Statement
          Dim updateSql As String = "UPDATE Quote " &amp; _
             "SET Status = '2', FirstName = @FirstName, LastName = @LastName, CompanyName = @CompanyName, Email = @Email, Phone = @Phone, Quantity = @Quantity, DesignInfo = @DesignInfo, CS1 = @CS1, CS2 = @CS2, Comments = @Comments " &amp; _
             "WHERE QuoteID = " &amp; QuoteID
          Dim UpdateCmd As New SqlCommand(updateSql, thisConnection)
          ' 2. Map Parameters
          'UpdateCmd.Parameters.Add("@Status", SqlDbType.Int, "Status")
          UpdateCmd.Parameters.Add("@FirstName", SqlDbType.NVarChar, 100, "FirstName")
          UpdateCmd.Parameters.Add("@LastName", SqlDbType.NVarChar, 100, "LastName")
          UpdateCmd.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 100, "CompanyName")
          UpdateCmd.Parameters.Add("@Email", SqlDbType.NVarChar, 200, "Email")
          UpdateCmd.Parameters.Add("@Phone", SqlDbType.NVarChar, 30, "Phone")
          UpdateCmd.Parameters.Add("@Quantity", SqlDbType.Int, 20, "Quantity")
          UpdateCmd.Parameters.Add("@DesignInfo", SqlDbType.NVarChar, 100, "DesignInfo")
          UpdateCmd.Parameters.Add("@CS1", SqlDbType.NVarChar, 20, "CS1")
          UpdateCmd.Parameters.Add("@CS2", SqlDbType.NVarChar, 20, "CS2")
          UpdateCmd.Parameters.Add("@Comments", SqlDbType.NVarChar, 1000, "Comments")
          ''''''''''''''
          'UpdateCmd.Parameters("@Status").Value = 2
          UpdateCmd.Parameters("@FirstName").Value = txtFirstName.Text
          UpdateCmd.Parameters("@LastName").Value = txtLastName.Text
          UpdateCmd.Parameters("@CompanyName").Value = txtCompanyName.Text
          UpdateCmd.Parameters("@Email").Value = txtEmailAddress.Text
          UpdateCmd.Parameters("@Phone").Value = txtPhoneNumber.Text
          UpdateCmd.Parameters("@Quantity").Value = txtQuantity1.Text
          UpdateCmd.Parameters("@DesignInfo").Value = drpDesignInfo1.SelectedValue
          UpdateCmd.Parameters("@CS1").Value = drpColoursSideOne1.SelectedValue
          Dim CS2 As String
          If drpDesignInfo1.SelectedValue = "1" Then
              CS2 = "na"
          Else
              CS2 = drpColoursSideTwo1.SelectedValue
          End If
          UpdateCmd.Parameters("@CS2").Value = CS2
          UpdateCmd.Parameters("@Comments").Value = txtComments.Text
          'QuoteID
          '''''''''''''''
          UpdateCmd.ExecuteNonQuery()
      Catch ex As SqlException
          ' Display error
          Response.Write("FAIL: " &amp; ex.Message)
      Finally
          ' Close Connection
          thisConnection.Close()
          Panel1.Visible = True
          Panel2.Visible = False
      End Try
  End Sub
  
  Protected Sub btnRequestAnother_Click(sender As Object, e As System.EventArgs) Handles btnRequestAnother.Click
      QuoteID = Nothing
      Response.Redirect(Request.RawUrl)
      Panel1.Visible = False
      Panel2.Visible = True
      'IsFirstTime = False
  End Sub
  Protected Sub drpColoursSideOne1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles drpColoursSideOne1.SelectedIndexChanged
      If drpDesignInfo1.SelectedValue = "2" Then
          drpColoursSideTwo1.SelectedValue = drpColoursSideOne1.SelectedValue
      End If
  End Sub
  End Class
  </code></pre>
  
  <p>Please excuse my messy code...</p>