title: Web request code wont run
body: <p>On the button click in my web page i run an sql statement, I also want to run a web request. I do not want to load anything from the web request, jsut run it. but here is the funny thing. The code that is the sql statement runs jsut fine, and then everything else below it just seems to not run.... at all. the server never receives the web request.</p>
  
  <p>if i copy the code to a page and run just the web request code it works. but here it does not.</p>
  
  <p>asp.net. thanks everyone. im stumped.</p>
  
  <pre><code>Imports System
  Imports System.Data
  Imports System.Web
  Imports System.Data.SqlClient
  
  Imports System.IO
  Imports System.Net
  Imports System.Text
  
  Partial Class _Default
  Inherits System.Web.UI.Page
  
  Protected Sub btnAddDeckSize_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddDeckSize.Click
      If txtDeckSize.Text &gt; "" And txtNewDeckPrice.Text &gt; "" Then
          Dim WasError As Boolean = False
          Dim SQLstring As String = "Server=server;Database=SecondLifeDatabases;Integrated Security=true"
          Dim SQLconn As SqlConnection
          Dim SQLcmd As New SqlCommand()
          SQLconn = New SqlConnection(SQLstring)
          Try
              SQLconn.Open()
              SQLcmd.Connection = SQLconn
              Try
                  SQLcmd.CommandText = ("INSERT INTO [SecondLifeDatabases].[dbo].[YuGiOh-DecksAndPrices]([DeckSize] ,[PriceInLindins])VALUES (" + txtDeckSize.Text + "," + txtNewDeckPrice.Text + ")")
                  SQLcmd.ExecuteNonQuery()
              Catch ex As Exception
                  Context.Response.Write("error:" + vbCrLf + " " + vbCrLf + "Unable to insert sql data, Type:" + vbCrLf + " " + vbCrLf + ex.Message)
                  WasError = True
                  SQLconn.Close()
              End Try
          Catch ex As Exception
              Context.Response.Write("error:" + vbCrLf + " " + vbCrLf + "Could not open database:" + vbCrLf + " " + vbCrLf + ex.Message)
              WasError = True
              SQLconn.Close()
          End Try
          SQLconn.Close()
          If WasError = False Then
              Context.Response.Redirect("~/YuGiOh.aspx")
          End If
      Else
          Context.Response.Write("Please check your values, something is Missing")
      End If
  </code></pre>
  
  <p>'START OF WHERE CODE SEEMS TO NOT RUN
  'THIS CODE ALONE RUNS ON ANOTHER PAGE
  'BUT HERE, EVEN THO THE CODE ABOVE RUNS, 
  'I NEVER SEE ANY RESULTS FROM THE CODE BLOW</p>
  
  <pre><code>    ' Create a request using a URL that can receive a post. 
      Dim request As WebRequest = WebRequest.Create("http://sim6103.agni.lindenlab.com:12046/cap/b936c974-cfab-c2ee-a184-4288fe0a10f8")
      ' Set the Method property of the request to POST.
      request.Method = "POST"
      ' Create POST data and convert it to a byte array.
      Dim postData As String = "This is a test that posts this string to a Web server."
      Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
      ' Set the ContentType property of the WebRequest.
      request.ContentType = "application/x-www-form-urlencoded"
      ' Set the ContentLength property of the WebRequest.
      request.ContentLength = byteArray.Length
      ' Get the request stream.
      Dim dataStream As Stream = request.GetRequestStream()
      ' Write the data to the request stream.
      dataStream.Write(byteArray, 0, byteArray.Length)
      ' Close the Stream object.
      dataStream.Close()
      ' Get the response.
      Dim response As WebResponse = request.GetResponse()
      ' Display the status.
      Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
      ' Get the stream containing content returned by the server.
      dataStream = response.GetResponseStream()
      ' Open the stream using a StreamReader for easy access.
      Dim reader As New StreamReader(dataStream)
      ' Read the content.
      Dim responseFromServer As String = reader.ReadToEnd()
      ' Display the content.
      Console.WriteLine(responseFromServer)
      ' Clean up the streams.
      reader.Close()
      dataStream.Close()
      response.Close()
  End Sub
  </code></pre>