We help IT Professionals succeed at work.

Setting and reading Cookies in VB.Net

megnin
megnin asked
on
I can't figure out what I'm doing wrong.  I copied the code from another of my web forms that works fine and I've tried several "Correct Answer" examples from EE using different methods.  My Cookies are always "Is Nothing"!

In my input form (three methods. two are commented out):
            ''Set cookies for values to be read when Employer logs in again - Method 1
            'Dim SYEPCookie As New HttpCookie("SYEPInfo")
            'SYEPCookie.Values("EmployerID") = txtPriKeyEmployerID.Text
            'SYEPCookie.Values("TaxID") = txtFedID.Text
            'SYEPCookie.Expires = DateTime.Now.AddMonths(12)
            'Response.Cookies.Add(SYEPCookie)
            ''Response.Cookies("SYEPInfo").Domain = "SYEP.WF1Broward.com"

            ''Set cookies for values to be read when Employer logs in again - Method 2
            'With Response
            '    .Cookies("SYEPInfo")("EmployerID") = txtPriKeyEmployerID.Text
            '    .Cookies("SYEPInfo")("TaxID") = txtFedID.Text
            '    .Cookies("SYEPInfo").Expires = DateTime.Now.AddMonths(12)
            'End With

            ''Set cookies for values to be read when Employer logs in again - Method 3
            Dim SYEPCookie As HttpCookie = New HttpCookie("SYEPInfo")
            SYEPCookie.Values.Add("EmployerID", txtPriKeyEmployerID.Text)
            SYEPCookie.Values.Add("TaxID", txtFedID.Text)
            SYEPCookie.Expires.AddMonths(12)
            Response.Cookies.Add(SYEPCookie)
            'Response.Cookies("SYEPInfo").Domain = "SYEP.WF1Broward.com"

Open in new window

Several tries here too...
In the Login page trying to read the Cookies.  I can't even get a Response.Write to show up.
If I leave out the "If Is Nothing" then I get "Object reference not set to an instance of an object":
        'If Not Request.Cookies("SYEPInfo") Is Nothing Then
        '    Response.Write(Request.Cookies("SYEPInfo")("EmployerID").ToString())
        '    Response.Write(Request.Cookies("SYEPInfo")("TaxID").ToString())
        'End If

        'If Not IsPostBack Then
        '    If Not Request.Cookies("SYEPInfo") Is Nothing Then
        '        Dim SYEPCookie As HttpCookie = Request.Cookies("SYEPInfo")
        '        txtEmployerID.Text = Server.HtmlEncode(Request.Cookies("SYEPInfo")("EmployerID"))
        '        txtTaxID.Text = Server.HtmlEncode(Request.Cookies("SYEPInfo")("TaxID"))
        '        'Response.Write(Server.HtmlEncode(Request.Cookies("EmployerID").Value) + "ok")
        '        Response.Write(Server.HtmlEncode(Request.Cookies("SYEPInfo")("EmployerID")))
        '        Response.Write(Server.HtmlEncode(Request.Cookies("SYEPInfo")("TaxID")))
        '    End If
        'End If

        'If Not Page.IsPostBack Then
        Dim SYEPCookie As HttpCookie = Request.Cookies("SYEPInfo")
        'If Not SYEPCookie Is Nothing Then
        Response.Write(SYEPCookie("EmployerID"))
        Response.Write(SYEPCookie("TaxID"))
        'End If
        'End If

Open in new window


Edit: I just noticed that in "Temporary Internet Files" where all the other Cookies live, what I find there are no cookies, but a "ScriptResource.axd?d=HcP8XCZx...=ffffffff823b7694" thing. So, my cookies don't seem to be getting cooked right.
Comment
Watch Question

Most Valuable Expert 2012
Top Expert 2014

Commented:
When are you creating the cookie? In a post back or in an updatepanel?

Author

Commented:
In a Submit Button click inside a "If Page.IsValid Then"

            ''Set cookies for values to be read when Employer logs in again - Method 1
            'Dim SYEPCookie As New HttpCookie("SYEPInfo1")
            'SYEPCookie.Values("EmployerID") = txtPriKeyEmployerID.Text
            'SYEPCookie.Values("TaxID") = txtFedID.Text
            'SYEPCookie.Expires = DateTime.Now.AddMonths(12)
            'Response.Cookies.Add(SYEPCookie)

            ''Set cookies for values to be read when Employer logs in again - Method 2
            'With Response
            '    .Cookies("SYEPInfo2")("EmployerID") = txtPriKeyEmployerID.Text
            '    .Cookies("SYEPInfo2")("TaxID") = txtFedID.Text
            '    .Cookies("SYEPInfo2").Expires = DateTime.Now.AddMonths(12)
            'End With

            ' ''Set cookies for values to be read when Employer logs in again - Method 3
            'Dim SYEPCookie3 As HttpCookie = New HttpCookie("SYEPInfo3")
            'SYEPCookie3.Values.Add("EmployerID", txtPriKeyEmployerID.Text)
            'SYEPCookie3.Values.Add("TaxID", txtFedID.Text)
            'SYEPCookie3.Expires.AddMonths(12)
            'Response.Cookies.Add(SYEPCookie3)
            ''Response.Cookies("SYEPInfo").Domain = "SYEP.WF1Broward.com"
End If

Open in new window

Most Valuable Expert 2012
Top Expert 2014

Commented:
But is the button inside an updatepanel or is it doing a full postback?

Author

Commented:
This should work, but it doesn't.  The cookie is not even written to "Temporary Internet Files".  The rest of the elements of the web page do go into Temporary Internet Files, but no cookie.
The Session variable I threw in as a test does not work either.
That very same code works just fine in another website.  The only thing I changed was the name of the cookie and the source of the value.
In SubmitButton on one .aspx page:
        Dim cookie As New HttpCookie("syep")
        cookie.Value = txtPriKeyEmployerID.Text
        cookie.Expires = DateTime.Now.AddMonths(3)
        Response.Cookies.Add(cookie)

        Session("eKey") = txtPriKeyEmployerID.Text

Open in new window

In Page_Load of another page:
        If Not Page.IsPostBack Then
            If Not Request.Cookies("syep") Is Nothing Then
                txtEmployerID.Text = Server.HtmlEncode(Request.Cookies("syep").Value)
            End If
        End If

Response.Write(Session("eKey"))

Open in new window

Author

Commented:
No, the button is not inside an Update Panel.
Most Valuable Expert 2012
Top Expert 2014

Commented:
So even


>Session("eKey") = txtPriKeyEmployerID.Text

is not working? Are you sure the code is executing?

Author

Commented:
Here is the button. It's not enabled now but it is enabled when an "I agree" checkbox is checked.
            <asp:Button ID="btnManageWorksites" runat="server" 
                        Text="Continue -&gt;" 
                        ValidationGroup="emp"
                        CausesValidation="True"  
                        Enabled="False" 
                        UseSubmitBehavior="True" TabIndex="170" CssClass="buttonSpace"
                        /> 

Open in new window

Author

Commented:
No.  Session() is not working either.
I'm using a QueryString to pass info from one page to the next and that's working fine.  

Author

Commented:
With the cookie, if I don't test for "Not Is Nothing" I get an "Object reference not set to an instance of an object" when I try to put it in a Response.Write for testing.

The Session variable doesn't give me that.  It's just empty.  If I concatinate some text onto the Session variable (on receiving end) I get only that test text on the receiving page with the Response.Write(Session("eKey") + "test text").
Most Valuable Expert 2012
Top Expert 2014

Commented:
Did you set a breakpoint on code behind the button to see if its executing?

Author

Commented:
I didn't set a breakpoint on the button, but the button has a call to a Sub that sends the data to a database and that goes.  It calls a sub that sends me an email and I get that and it creates a QueryString and that's working.
Dim url As String
            url = "Worksite1.aspx?eKey=" + txtPriKeyEmployerID.Text + _
            "&eName=" + txtEmployerName.Text + _

Open in new window


The simple bit of Cookie code is the only other thing in the Submit button.  The same code creates a cooking just fine in another web application.
Most Valuable Expert 2012
Top Expert 2014

Commented:
Only thing left to do is to step through the code to see if the code is executing. If it is executing then we would investigate why its not creating the cookie on the client side.

Author

Commented:
I set a breakpoint on the Cookie creating code and then debug ran the page and got this:

Server Error in '/SYEP' Application.
--------------------------------------------------------------------------------

The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /SYEP/Employer1.aspx


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237
Most Valuable Expert 2012
Top Expert 2014

Commented:
Is that the URL of the page containing the code? Did you add this cookie code recently? I suspect that site is running precompiled with a DLL in bin folder and the changes you made are not making it to the DLL.

Author

Commented:
I made changes to the page and other pages in the site all weekend long.  The only thing that didn't work is the cookies.
Most Valuable Expert 2012
Top Expert 2014

Commented:
Do you have a projectname.dll in the bin directory?

Author

Commented:
No, just the AjaxXontrolToolkit.dll.

Author

Commented:
The URL to the Submit form is https://syep.wf1broward.com/Employer1.aspx
The URL to the Login page to receive the cookie value is https://syep.wf1broward.com/Login.aspx
Most Valuable Expert 2012
Top Expert 2014

Commented:
Given that the session value is not being created, I suspect the code segment is not executing at all. Can you show the full code (stripping out sensitive info)?

Author

Commented:
Yes. Do you just want the .vb or the .aspx and .vb?

Author

Commented:
Well, there's nothing sensitive. My connection string is in the config.sys.
The submit button is:  btnManageWorksites_Click
and starts on line 46.  I have three methods of creating cookies commented out there.

Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls
Imports System.Text.RegularExpressions

Partial Class Employer1
    Inherits System.Web.UI.Page
    Dim priKeyEmployers As Integer ' = DBCmd.ExecuteScalar()  'Moved to Global scope

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Session.Clear()

        If cbConfirmUnderstand.Checked = True Then
            btnManageWorksites.Enabled = True
        Else
            btnManageWorksites.Enabled = False
        End If
	End Sub

	Protected Sub cbSameAsAbove_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbSameAsAbove.CheckedChanged
		If cbSameAsAbove.Checked = True Then
			txtContactProgram.Text = txtContactContract.Text
			txtContactProgramAddress.Text = txtCompanyStreet.Text
			txtContactProgramCity.Text = txtCompanyCity.Text
			txtContactProgramState.Text = txtCompanyState.Text
			txtContactProgramZip.Text = txtCompanyZip.Text
			txtContactProgramTitle.Text = txtContactContractTitle.Text
			txtContactProgramPhone.Text = txtCompanyContractContactTelephone.Text
			txtContactProgramFAX.Text = txtCompanyContractContactFAX.Text
			txtContactProgramCell.Text = txtCompanyContractContactCell.Text
			txtContactProgramEmail.Text = txtCompanyContractContactEmail.Text
		Else
			txtContactProgram.Text = ""
			txtContactProgramAddress.Text = ""
			txtContactProgramCity.Text = ""
			txtContactProgramState.Text = ""
			txtContactProgramZip.Text = ""
			txtContactProgramTitle.Text = ""
			txtContactProgramPhone.Text = ""
			txtContactProgramFAX.Text = ""
			txtContactProgramCell.Text = ""
			txtContactProgramEmail.Text = ""
		End If
	End Sub

	Protected Sub btnManageWorksites_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnManageWorksites.Click
        'Submit Button
        If Page.IsValid Then
            Call SendDataToEmployers()
            Call SendEmailToManager()                                           'City of Fort Lauderdale error  Restore these after City of Fort Lauderdale
            'Response.Redirect("https://syep.wf1broward.com/Worksite1.aspx")     'City of Fort Lauderdale Restore after City of Fort Lauderdale

            'Response.Redirect("Worksite1.aspx?priKeyEmployersID=" + priKeyEmployers.ToString)
            'Server.Transfer("Worksite1.aspx?priKeyEmployersID=" + priKeyEmployers.ToString)

            'Begin City of Fort Lauderdale 
            Dim url As String
            url = "Worksite1.aspx?eKey=" + txtPriKeyEmployerID.Text + _
            "&eName=" + txtEmployerName.Text + _
            "&eAddress=" + txtCompanyStreet.Text + _
            "&eCity=" + txtCompanyCity.Text + _
            "&eZip=" + txtCompanyZip.Text + _
            "&cName=" + txtContactContract.Text + _
            "&cTitle=" + txtContactContractTitle.Text + _
            "&cPhone=" + txtCompanyContractContactTelephone.Text + _
            "&cFax=" + txtCompanyContractContactFAX.Text + _
            "&cCell=" + txtCompanyContractContactCell.Text + _
            "&cEmail=" + txtCompanyContractContactEmail.Text
            Response.Redirect(url)
            'End City of Fort Lauderdale

            ''Set cookies for values to be read when Employer logs in again - Method 1
            'Dim SYEPCookie As New HttpCookie("SYEPInfo1")
            'SYEPCookie.Values("EmployerID") = txtPriKeyEmployerID.Text
            'SYEPCookie.Values("TaxID") = txtFedID.Text
            'SYEPCookie.Expires = DateTime.Now.AddMonths(12)
            'Response.Cookies.Add(SYEPCookie)

            ''Set cookies for values to be read when Employer logs in again - Method 2
            'With Response
            '    .Cookies("SYEPInfo2")("EmployerID") = txtPriKeyEmployerID.Text
            '    .Cookies("SYEPInfo2")("TaxID") = txtFedID.Text
            '    .Cookies("SYEPInfo2").Expires = DateTime.Now.AddMonths(12)
            'End With

            ' ''Set cookies for values to be read when Employer logs in again - Method 3
            'Dim SYEPCookie3 As HttpCookie = New HttpCookie("SYEPInfo3")
            'SYEPCookie3.Values.Add("EmployerID", txtPriKeyEmployerID.Text)
            'SYEPCookie3.Values.Add("TaxID", txtFedID.Text)
            'SYEPCookie3.Expires.AddMonths(12)
            'Response.Cookies.Add(SYEPCookie3)
            ' ''Response.Cookies("SYEPInfo").Domain = "SYEP.WF1Broward.com"


        End If

        Dim cookie As New HttpCookie("syep")
        cookie.Value = txtPriKeyEmployerID.Text
        cookie.Expires = DateTime.Now.AddMonths(3)
        Response.Cookies.Add(cookie)

        ''Restort this after City of Fort Lauderdale
        Session("eKey") = txtPriKeyEmployerID.Text
        'Session("eTax") = txtFedID.Text
        'Session("eName") = txtEmployerName.Text
        'Session("eAddress") = txtCompanyStreet.Text
        'Session("eCity") = txtCompanyCity.Text
        'Session("eZip") = txtCompanyZip.Text
        'Session("cName") = txtContactContract.Text
        'Session("cTitle") = txtContactContractTitle.Text
        'Session("cPhone") = txtCompanyContractContactTelephone.Text
        'Session("cFax") = txtCompanyContractContactFAX.Text
        'Session("cCell") = txtCompanyContractContactCell.Text
        'Session("cEmail") = txtCompanyContractContactEmail.Text

        'Response.Redirect("Worksite1.aspx?priKeyEmployersID={0}", priKeyEmployers)
        'priKeyEmployersID=priKeyEmployers")

        'Save Company Information to database, any session state saving and open Worksites Form

        'Server.Transfer("https://syep.wf1broward.com/Applicant.aspx")
        'Response.Redirect("https://syep.wf1broward.com/Applicant.aspx")
        'http://www.developer.com/net/asp/article.php/3299641

        'Firstly, transferring to another page using Server.Transfer conserves server resources. Instead of telling the browser to redirect, 
        'it simply changes the "focus" on the Web server and transfers the request. This means you don't get quite as many HTTP requests coming through, 
        'which therefore eases the pressure on your Web server and makes your applications run faster.
        'But watch out: because the "transfer" process can work on only those sites running on the server, you can't use Server.Transfer to send the user 
        'to an external site. Only Response.Redirect can do that.
        'Secondly, Server.Transfer maintains the original URL in the browser. This can really help streamline data entry techniques, although it may make 
        'for confusion when debugging.
        '        That() 's not all: The Server.Transfer method also has a second parameter—"preserveForm". If you set this to True, 
        'using a statement such as Server.Transfer("WebForm2.aspx", True), the existing query string and any form variables will still be available 
        'to the page you are transferring to.
        'For example, if your WebForm1.aspx has a TextBox control called TextBox1 and you transferred to WebForm2.aspx with the preserveForm 
        'parameter set to True, you'd be able to retrieve the value of the original page TextBox control by referencing Request.Form("TextBox1").
        'This technique is great for wizard-style input forms split over multiple pages. But there's another thing you'll want to watch out for 
        'when using the preserveForm parameter. ASP.NET has a bug whereby, in certain situations, an error will occur when attempting to transfer 
        'the form and query string values. You'll find this documented at http://support.microsoft.com/default.aspx?id=kb;en-us;Q316920.
        'The unofficial solution is to set the enableViewStateMac property to True on the page you'll be transferring to, then set it back to False. 
        'This records that you want a definitive False value for this property and resolves the bug.
    End Sub

	Protected Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
		' Save and Exit
		'Save Company Information to database and go back to Home Page
		'Create and call a Subroutine to save the Company information since both buttons will save the same data.
		If Page.IsValid Then
			Call SendDataToEmployers()
            Call SendEmailToManager()

			'Response.Redirect("https://syep.wf1broward.com/default.htm")
			Response.Redirect("https://syep.wf1broward.com/EmployerConfirmation1.aspx")
			'Server.Transfer("default.htm")
		End If

        'Response.Redirect("https://syep.wf1broward.com")
	End Sub

	Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
		'I'm just clearing all the fields for testing purposes.  I don't necessarily have to for the working version.
		txtEmployerName.Text = ""
		ddlOrganizationType.SelectedIndex = "0"
		txtFedID.Text = ""
		txtContactContract.Text = ""
		txtCompanyStreet.Text = ""
		txtCompanyCity.Text = ""
		txtCompanyState.Text = ""
		txtCompanyZip.Text = ""
		txtContactContractTitle.Text = ""
		txtCompanyContractContactTelephone.Text = ""
		txtCompanyContractContactFAX.Text = ""
		txtCompanyContractContactCell.Text = ""
		txtCompanyContractContactEmail.Text = ""

		txtContactProgram.Text = ""
		txtContactProgramAddress.Text = ""
		txtContactProgramCity.Text = ""
		txtContactProgramState.Text = ""
		txtContactProgramZip.Text = ""
		txtContactProgramTitle.Text = ""
		txtContactProgramPhone.Text = ""
		txtContactProgramFAX.Text = ""
		txtContactProgramCell.Text = ""
		txtContactProgramEmail.Text = ""

		Server.Transfer("default.htm")

	End Sub

	Protected Sub btnTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTest.Click
		'This is just to fill the fields with test data quickly.
        txtEmployerName.Text = "zzz TEST Inc. 123"
		ddlOrganizationType.SelectedIndex = "2"
		txtFedID.Text = "11-0000000"
		txtContactContract.Text = "XXX Contract Person"
        txtCompanyStreet.Text = "6301 NW 5th Way, Suite 3000"
        txtCompanyCity.Text = "Fort Lauderdale"
		txtCompanyState.Text = "FL"
        txtCompanyZip.Text = "33309"
        txtContactContractTitle.Text = "Contract Person Title"
		txtCompanyContractContactTelephone.Text = "111-111-1111"
        txtCompanyContractContactFAX.Text = "222-222-2222"
        txtCompanyContractContactCell.Text = "333-333-3333"
		txtCompanyContractContactEmail.Text = "foo@bar.com"

		txtContactProgram.Text = "XXX Program Person"
		txtContactProgramAddress.Text = "2488 Park Plaza"
		txtContactProgramCity.Text = "San Jose"
		txtContactProgramState.Text = "CA"
		txtContactProgramZip.Text = "88888"
		txtContactProgramTitle.Text = "Contact Title"
		txtContactProgramPhone.Text = "(888) 888-8888"
		txtContactProgramFAX.Text = "(888) 888-8888"
		txtContactProgramCell.Text = "(888) 888-8888"
        txtContactProgramEmail.Text = "Working@Home.com"
        radOrgHasContract.SelectedIndex = 1
        radStimulus.SelectedIndex = 0

	End Sub


	Protected Sub SendDataToEmployers()

		'Cache("eName") = txtEmployerName.Text & " Go Figure (Testing)"

        'Try using this to point to the connection string in the web.config.  Then it only needs to be changed in one place.
        'ConfigurationManager.ConnectionStrings["SYEP2007ConnectionString1"].ConnectionString
        Dim DBConn As New SqlConnection(ConfigurationManager.ConnectionStrings("SYEP2007ConnectionString1").ConnectionString)

        'Dim DBConn As New SqlConnection("UID=dmegnin;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SYEP2007;Data Source=MSQLServ.broward-workforce.org;Packet Size=4096;")
        'Dim DBConn As New SqlConnection("Integrated Security=SSPI;Initial Catalog=SYEP2007;Data Source=Windows7\SQLEXPRESS;")
        Dim DBCmd As New SqlCommand
        DBConn.Open()

		Try
			'Add Insert Statement 
            ' DBCmd = New SqlCommand("INSERT INTO Employers(keyEmployerID,txtEmployerName,ddlOrganizationType,txtFedID,txtContactContract,txtContactContractTitle,txtCompanyStreet,txtCompanyCity,txtCompanyState,txtCompanyZip,txtCompanyContractContactTelephone,txtCompanyContractContactFAX,txtCompanyContractContactCell,txtCompanyContractContactEmail,txtContactProgram,txtContactProgramTitle,txtContactProgramAddress,txtContactProgramCity,txtContactProgramState,txtContactProgramZip,txtContactProgramPhone,txtContactProgramFAX,txtContactProgramCell,txtContactProgramEmail,txtWorksitesRequestedNumber,ddlOrgHasContract,ddlConfirmUnderstand,ApplicationDateEmployer) VALUES (@txtPriKeyEmployerID,@txtEmployerName,@ddlOrganizationType,@txtFedID,@txtContactContract,@txtContactContractTitle,@txtCompanyStreet,@txtCompanyCity,@txtCompanyState,@txtCompanyZip,@txtCompanyContractContactTelephone,@txtCompanyContractContactFAX,@txtCompanyContractContactCell,@txtCompanyContractContactEmail,@txtContactProgram,@txtContactProgramTitle,@txtContactProgramAddress,@txtContactProgramCity,@txtContactProgramState,@txtContactProgramZip,@txtContactProgramPhone,@txtContactProgramFAX,@txtContactProgramCell,@txtContactProgramEmail,@txtWorksitesRequestedNumber,@ddlOrgHasContract,@ddlConfirmUnderstand,getdate())", DBConn)
            DBCmd = New SqlCommand("SET NOCOUNT ON; INSERT INTO Employers(txtEmployerName,ddlOrganizationType,txtFedID,txtContactContract,txtContactContractTitle,txtCompanyStreet,txtCompanyCity,txtCompanyState,txtCompanyZip,txtCompanyContractContactTelephone,txtCompanyContractContactFAX,txtCompanyContractContactCell,txtCompanyContractContactEmail,txtContactProgram,txtContactProgramTitle,txtContactProgramAddress,txtContactProgramCity,txtContactProgramState,txtContactProgramZip,txtContactProgramPhone,txtContactProgramFAX,txtContactProgramCell,txtContactProgramEmail,txtWorksitesRequestedNumber,ddlOrgHasContract,ddlConfirmUnderstand,Stimulus,ApplicationDateEmployer) VALUES (@txtEmployerName,@ddlOrganizationType,@txtFedID,@txtContactContract,@txtContactContractTitle,@txtCompanyStreet,@txtCompanyCity,@txtCompanyState,@txtCompanyZip,@txtCompanyContractContactTelephone,@txtCompanyContractContactFAX,@txtCompanyContractContactCell,@txtCompanyContractContactEmail,@txtContactProgram,@txtContactProgramTitle,@txtContactProgramAddress,@txtContactProgramCity,@txtContactProgramState,@txtContactProgramZip,@txtContactProgramPhone,@txtContactProgramFAX,@txtContactProgramCell,@txtContactProgramEmail,@txtWorksitesRequestedNumber,@ddlOrgHasContract,@ddlConfirmUnderstand,@radStimulus,getdate()); Select SCOPE_IDENTITY()", DBConn)
            'Doesn't work for entries made at different locations. Session Required. 'DBCmd = New SqlCommand("IF (SELECT COUNT(txtFedID) FROM Employers WHERE (txtFedID = @txtFedID)) > 0  SELECT -1 as error  FROM Employers ELSE BEGIN SET NOCOUNT ON; INSERT INTO Employers(txtEmployerName,ddlOrganizationType,txtFedID,txtContactContract,txtContactContractTitle,txtCompanyStreet,txtCompanyCity,txtCompanyState,txtCompanyZip,txtCompanyContractContactTelephone,txtCompanyContractContactFAX,txtCompanyContractContactCell,txtCompanyContractContactEmail,txtContactProgram,txtContactProgramTitle,txtContactProgramAddress,txtContactProgramCity,txtContactProgramState,txtContactProgramZip,txtContactProgramPhone,txtContactProgramFAX,txtContactProgramCell,txtContactProgramEmail,txtWorksitesRequestedNumber,ddlOrgHasContract,ddlConfirmUnderstand,Stimulus,ApplicationDateEmployer) VALUES (@txtEmployerName,@ddlOrganizationType,@txtFedID,@txtContactContract,@txtContactContractTitle,@txtCompanyStreet,@txtCompanyCity,@txtCompanyState,@txtCompanyZip,@txtCompanyContractContactTelephone,@txtCompanyContractContactFAX,@txtCompanyContractContactCell,@txtCompanyContractContactEmail,@txtContactProgram,@txtContactProgramTitle,@txtContactProgramAddress,@txtContactProgramCity,@txtContactProgramState,@txtContactProgramZip,@txtContactProgramPhone,@txtContactProgramFAX,@txtContactProgramCell,@txtContactProgramEmail,@txtWorksitesRequestedNumber,@ddlOrgHasContract,@ddlConfirmUnderstand,@radStimulus,getdate()); Select SCOPE_IDENTITY() End", DBConn)
			'Add Database Parameters
			DBCmd.Parameters.Add("@txtEmployerName", SqlDbType.VarChar).Value = txtEmployerName.Text
			DBCmd.Parameters.Add("@ddlOrganizationType", SqlDbType.VarChar).Value = ddlOrganizationType.Text
			DBCmd.Parameters.Add("@txtFedID", SqlDbType.VarChar).Value = txtFedID.Text
			DBCmd.Parameters.Add("@txtContactContract", SqlDbType.VarChar).Value = txtContactContract.Text
			DBCmd.Parameters.Add("@txtContactContractTitle", SqlDbType.VarChar).Value = txtContactContractTitle.Text
			DBCmd.Parameters.Add("@txtCompanyStreet", SqlDbType.VarChar).Value = txtCompanyStreet.Text
			DBCmd.Parameters.Add("@txtCompanyCity", SqlDbType.VarChar).Value = txtCompanyCity.Text
			DBCmd.Parameters.Add("@txtCompanyState", SqlDbType.VarChar).Value = txtCompanyState.Text
			DBCmd.Parameters.Add("@txtCompanyZip", SqlDbType.VarChar).Value = txtCompanyZip.Text
			DBCmd.Parameters.Add("@txtCompanyContractContactTelephone", SqlDbType.VarChar).Value = txtCompanyContractContactTelephone.Text
			DBCmd.Parameters.Add("@txtCompanyContractContactFAX", SqlDbType.VarChar).Value = txtCompanyContractContactFAX.Text
			DBCmd.Parameters.Add("@txtCompanyContractContactCell", SqlDbType.VarChar).Value = txtCompanyContractContactCell.Text
			DBCmd.Parameters.Add("@txtCompanyContractContactEmail", SqlDbType.VarChar).Value = txtCompanyContractContactEmail.Text
			DBCmd.Parameters.Add("@txtContactProgram", SqlDbType.VarChar).Value = txtContactProgram.Text
			DBCmd.Parameters.Add("@txtContactProgramTitle", SqlDbType.VarChar).Value = txtContactProgramTitle.Text
			DBCmd.Parameters.Add("@txtContactProgramAddress", SqlDbType.VarChar).Value = txtContactProgramAddress.Text
			DBCmd.Parameters.Add("@txtContactProgramCity", SqlDbType.VarChar).Value = txtContactProgramCity.Text
			DBCmd.Parameters.Add("@txtContactProgramState", SqlDbType.VarChar).Value = txtContactProgramState.Text
			DBCmd.Parameters.Add("@txtContactProgramZip", SqlDbType.VarChar).Value = txtContactProgramZip.Text
			DBCmd.Parameters.Add("@txtContactProgramPhone", SqlDbType.VarChar).Value = txtContactProgramPhone.Text
			DBCmd.Parameters.Add("@txtContactProgramFAX", SqlDbType.VarChar).Value = txtContactProgramFAX.Text
			DBCmd.Parameters.Add("@txtContactProgramCell", SqlDbType.VarChar).Value = txtContactProgramCell.Text
			DBCmd.Parameters.Add("@txtContactProgramEmail", SqlDbType.VarChar).Value = txtContactProgramEmail.Text
			DBCmd.Parameters.Add("@txtWorksitesRequestedNumber", SqlDbType.VarChar).Value = "0"	' txtWorksitesRequestedNumber.Text  'We aren't entering a number anymore
			DBCmd.Parameters.Add("@ddlOrgHasContract", SqlDbType.VarChar).Value = radOrgHasContract.SelectedValue
			DBCmd.Parameters.Add("@ddlConfirmUnderstand", SqlDbType.VarChar).Value = cbConfirmUnderstand.Checked
            'DBCmd.Parameters.Add("@Participated2007", SqlDbType.VarChar).Value = radParticipated2007.SelectedValue
            'DBCmd.Parameters.Add("@Participate2009", SqlDbType.VarChar).Value = "Yes"
            DBCmd.Parameters.Add("@radStimulus", SqlDbType.VarChar).Value = radStimulus.SelectedValue
            'DBCmd.Parameters.Add("@radStimulus", SqlDbType.VarChar).Value = "CSC"
            'DBCmd.Parameters.Add("@ApplicationDateEmployer", SqlDbType.SmallDateTime).Value = GetDate() 'A Parameter is no used here. The GetDate() function is in the INSERT "VALUE" statement

            'Dim priKeyEmployers As Integer = DBCmd.ExecuteScalar()  'Moved to Global scope
            priKeyEmployers = DBCmd.ExecuteScalar()  'Moved to Global scope

			'Response.Write(priKeyEmployers)

			txtPriKeyEmployerID.Text = priKeyEmployers
			'txtForeignKeyWsEmployerID.Text = priKeyEmployers   'This TextBox moved to Worksites1.aspx
			'txtForeignKeyPosEmployerID.Text = priKeyEmployers  'This TextBox moved to JobTitles1.aspx

            ''This is redundant it's sent in the Submit button click
            'Session("eKey") = priKeyEmployers.ToString
            'Session("eName") = txtEmployerName.Text
            'Session("eAddress") = txtCompanyStreet.Text
            'Session("eCity") = txtCompanyCity.Text
            'Session("eZip") = txtCompanyZip.Text
            'Session("cName") = txtContactContract.Text
            'Session("cTitle") = txtContactContractTitle.Text
            'Session("cPhone") = txtCompanyContractContactTelephone.Text
            'Session("cFax") = txtCompanyContractContactFAX.Text
            'Session("cCell") = txtCompanyContractContactCell.Text
            'Session("cEmail") = txtCompanyContractContactEmail.Text

            'Need to check for existing FEID, then query for that FEID AND EmployerName to get EmployerID for Session
            'If priKeyEmployers < 0 Then
            '    'Server.Transfer("ApplicantDup.aspx")
            '    Response.Redirect("EmployerDup.aspx")
            'Else
            '    Session("EmployerID") = priKeyEmployers
            'End If

		Catch exp As Exception
			Response.Write(exp)
		End Try
		'Close Database connection 
		DBCmd.Dispose()
		DBConn.Close()
		DBConn = Nothing

	End Sub

	Protected Sub SendEmailToManager()
		'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Start Automatic Email routine  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		Dim smtpClient As Net.Mail.SmtpClient = New Net.Mail.SmtpClient()
		Dim message As Net.Mail.MailMessage = New Net.Mail.MailMessage()
		Dim messageBody As String = ""
		'Prepare two email addresses
        Dim fromAddress As New Net.Mail.MailAddress("syep09@wf1broward.com", "SYEP 2012 Job Order")
        Dim toAddress1 As New Net.Mail.MailAddress("LKing@wf1broward.com")      '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Email Recipient(s) 
        Dim toAddress2 As New Net.Mail.MailAddress("BLauzon@wf1broward.com")
        Dim toAddress3 As New Net.Mail.MailAddress("DMegnin@wf1broward.com")
        Dim toAddress4 As New Net.Mail.MailAddress("YMillwood@wf1broward.com")
        Dim toAddress5 As New Net.Mail.MailAddress("VChin@wf1broward.com")
       'Prepare the mail message
        'Restore this to the Body after City of Fort Lauderdale
		message.IsBodyHtml = True
		message.From = fromAddress
        message.To.Add(toAddress1)
        message.CC.Add(toAddress2)
        message.CC.Add(toAddress3)
        'message.CC.Add(toAddress4)
        'message.CC.Add(toAddress5)

        message.Subject = "SYEP 2012 Job Order: " & priKeyEmployers
        messageBody = "New Employer Job Order: " & vbCrLf 
         messageBody = messageBody & "<div style='margin-left:5em; color:#006666;'>" 
         messageBody = messageBody & "<br /><b><u>SYEP 2012 Employer Information</u>:</b> " 
         messageBody = messageBody & vbCrLf & vbCrLf 
         messageBody = messageBody & "<br /><br /><b>Employer:</b> " & vbTab & txtEmployerName.Text & "  <font color='red'>(" & ddlOrganizationType.Text & ")</font>" & vbCrLf 
         messageBody = messageBody & "<br /><br /><b>Employer ID:</b> " & vbTab & txtPriKeyEmployerID.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>Contract Contact:</b> " & vbTab & txtContactContract.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>Title:</b> " & vbTab & txtContactContractTitle.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>Address:</b> " & vbTab & txtCompanyStreet.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>City:</b> " & vbTab & txtCompanyCity.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>State:</b> " & vbTab & txtCompanyState.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>Zip:</b> " & vbTab & vbTab & txtCompanyZip.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>Phone:</b> " & vbTab & txtCompanyContractContactTelephone.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>FAX:</b> " & vbTab & vbTab & txtCompanyContractContactFAX.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>Cell:</b> " & vbTab & txtCompanyContractContactCell.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>Email:</b> " & vbTab & txtCompanyContractContactEmail.Text & vbCrLf 
         messageBody = messageBody & vbCrLf 
         messageBody = messageBody & "<br /><br /><b>Program Contact:</b> " & vbTab & txtContactProgram.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>Title:</b> " & vbTab & txtContactProgramTitle.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>Address:</b> " & vbTab & txtContactProgramAddress.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>City:</b> " & vbTab & txtContactProgramCity.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>State:</b> " & vbTab & txtContactProgramState.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>Zip:</b> " & vbTab & vbTab & txtContactProgramZip.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>Phone:</b> " & vbTab & txtContactProgramPhone.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>FAX:</b> " & vbTab & vbTab & txtContactProgramFAX.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>Cell:</b> " & vbTab & txtContactProgramCell.Text & vbCrLf 
         messageBody = messageBody & "<br /><b>Email:</b> " & vbTab & txtContactProgramEmail.Text & vbCrLf 
         messageBody = messageBody & "<br /><br /><b>Has Contract with WorkForce One?:</b> " & vbTab & radOrgHasContract.SelectedValue & vbCrLf 
         messageBody = messageBody & "<br /><br /><b>CSC or WIA Program?:</b> " & vbTab & radStimulus.SelectedValue & vbCrLf 
         messageBody = messageBody & "<br /><br /><br /><TABLE height='185' cellSpacing='0' cellPadding='0'><TBODY>" 
         messageBody = messageBody & "<TR><TD vAlign='top' align='left' width='600' height='185'><TABLE cellSpacing='0' cellPadding='0' width='100%'><TBODY>" 
         messageBody = messageBody & "<TR><TD><DIV><P><B><FONT face='arial' size='2'><FONT color='#006d75'>SYEP 2012 Job Order</FONT></B><BR>Contact David for any technical issues.<BR>" 
         messageBody = messageBody & "<FONT face='arial' color='#8c004c' size='2'>(954) 202-3830 Ext. 3030</FONT></P><P>6301 NW 5th Way, Suite 3000<BR>" 
         messageBody = messageBody & "Fort Lauderdale, FL  33309<BR>(954) 535-2301</P><P><a href='mailto:DMegnin@wf1broward.com' style='text-decoration:none'>" 
         messageBody = messageBody & "<FONT face='arial' color='#8c004c' size='2'><B>DMegnin@wf1broward.com</B></FONT></A><BR> <a href='https://syep.wf1broward.com/Applicant.aspx' " 
         messageBody = messageBody & "style='text-decoration:none; color:black'>SYEP.WF1Broward.com</a></P></DIV></FONT></TD></TR></TBODY></TABLE></TD></TR></TBODY>" 
         messageBody = messageBody & "</TABLE></B><FONT face='arial' color='#bbbbbb' size='1'>This message is intended only for the use of the individual or entity to which " 
         messageBody = messageBody & "it is addressed and may contain information that is privileged, confidential and exempt from disclosure under applicable law."
		'"<br /><br /><b>Worksites Requested:</b> " & vbTab & txtWorksitesRequestedNumber.Text & vbCrLf & _
		message.Body = messageBody

		'Set server details
		smtpClient.Host = "ExchServ"
		'Send the email
		Try
			smtpClient.Send(message)
		Catch exp As Exception
			Response.Write(exp)
		End Try
		'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< End Automatic Email routine  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	End Sub

	Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
		'Log In

        '      'Login Commented out on Employer1.aspx  Now just sending to Login.aspx page
        'Cache("eKey") = TextBox1.Text
        ''Cache("wKey") = ""

        ''Dim Conn As New SqlConnection(ConfigurationManager.AppSettings("connectionstring"))
        'Dim DBConn As New SqlConnection("UID=dmegnin;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SYEP2007;Data Source=MSQLServ.broward-workforce.org;Packet Size=4096;")
        'Dim SQLText As String
        'SQLText = "SELECT txtEmployerName, txtCompanyStreet, txtCompanyCity,txtCompanyZip, txtContactContract,txtContactContractTitle, txtCompanyContractContactTelephone,txtCompanyContractContactFAX,txtCompanyContractContactCell, txtCompanyContractContactEmail FROM Employers WHERE (keyEmployerID = '" + TextBox1.Text + "') AND (txtFedID = '" + TextBox2.Text + "')"
        'Dim dr As SqlDataReader
        'Dim DBCmd As SqlCommand = New SqlCommand(SQLText, DBConn)
        'Try
        '	DBConn.Open()
        '	dr = DBCmd.ExecuteReader
        '	If dr.HasRows Then
        '		While dr.Read()
        '			'Cache("eKey") = dr("keyEmployerID")
        '			Cache("eName") = dr("txtEmployerName")
        '			Cache("eAddress") = dr("txtCompanyStreet")
        '			Cache("eCity") = dr("txtCompanyCity")
        '			Cache("eZip") = dr("txtCompanyZip")
        '			Cache("cName") = dr("txtContactContract")
        '			Cache("cTitle") = dr("txtContactContractTitle")
        '			Cache("cPhone") = dr("txtCompanyContractContactTelephone")
        '			Cache("cFax") = dr("txtCompanyContractContactFAX")
        '			Cache("cCell") = dr("txtCompanyContractContactCell")
        '			Cache("cEmail") = dr("txtCompanyContractContactEmail")
        '		End While
        '	Else
        '		lblLoginIncorrect.Text = "Login Incorrect"
        '		Exit Sub
        '	End If
        'Catch exp As Exception
        '	Response.Write(exp)
        'Finally
        '	DBCmd.Dispose()
        '	DBConn.Close()
        '	DBConn = Nothing
        'End Try

        'Response.Redirect("https://syep.wf1broward.com/Worksite1.aspx")
        Response.Redirect("https://syep.wf1broward.com/Login.aspx")

	End Sub

    Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        Server.Transfer("Login.aspx")
    End Sub
End Class

Open in new window

Author

Commented:
Here is the Login page.  The receiving end of the cookie values.  (The Submit page is above.)
Cookie code is commented out here too, since I was trying several different methods.
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls

Partial Class Login
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'If Me.IsPostBack then
        '    Response.Write("You can only fill out the Application one time.  Duplicate Applications will be grounds for rejection. If you had a problem filling out the Applicaton Call (954) 202-3830")
        'End If
        'Dim ButtonInView As Button = DirectCast(Me.LoginView1.FindControl("Button3"), Button)

        'Dim bt As String = ButtonInView.Text.ToString
        'Label1.text = bt

        'If Not Request.Cookies("SYEPInfo") Is Nothing Then
        'Response.Write(Request.Cookies("SYEPInfo1")("EmployerID").ToString())
        ' Response.Write(Request.Cookies("SYEPInfo1")("TaxID").ToString())

        ' Response.Write(Request.Cookies("SYEPInfo2")("EmployerID").ToString())
        ' Response.Write(Request.Cookies("SYEPInfo2")("TaxID").ToString())

        ' Response.Write(Request.Cookies("SYEPInfo3")("EmployerID").ToString())
        ' Response.Write(Request.Cookies("SYEPInfo3")("TaxID").ToString())
        'End If

        'If Not IsPostBack Then
        'If Not Request.Cookies("SYEPInfo") Is Nothing Then
        ' Dim SYEPCookie As HttpCookie = Request.Cookies("SYEPInfo")
        'txtEmployerID.Text = Server.HtmlEncode(Request.Cookies("SYEPInfo")("EmployerID"))
        ' txtTaxID.Text = Server.HtmlEncode(Request.Cookies("SYEPInfo")("TaxID"))
        'Response.Write(Server.HtmlEncode(Request.Cookies("EmployerID").Value) + "ok")
        ' Response.Write(Server.HtmlEncode(Request.Cookies("SYEPInfo1")("EmployerID")))
        ' Response.Write(Server.HtmlEncode(Request.Cookies("SYEPInfo2")("TaxID")))
        'End If
        ' End If

        'If Not Page.IsPostBack Then
        'Dim SYEPCookie As HttpCookie = Request.Cookies("SYEPInfo")
        'If Not SYEPCookie Is Nothing Then
        'Response.Write(SYEPCookie("EmployerID"))
        ' Response.Write(SYEPCookie("TaxID"))
        'End If
        'End If

        ''Set cookies for values to be read when Employer logs in again
        'Dim cookieEmpID As New HttpCookie("EmployerID")
        'cookieEmpID.Value = priKeyEmployers
        'cookieEmpID.Expires = DateTime.Now.AddMonths(12)
        'Response.Cookies.Add(cookieEmpID)

        'Dim cookieTaxID As New HttpCookie("TaxID")
        'cookieTaxID.Value = txtFedID.Text
        'cookieTaxID.Expires = DateTime.Now.AddMonths(12)
        'Response.Cookies.Add(cookieTaxID)


        'Response.Write(Session("eKey") + " - 1 ")
        If Not Page.IsPostBack Then
            If Not Session("eKey") Is Nothing Then
                txtEmployerID.Text = Session("eKey")
                txtTaxID.Text = Session("eTax")
                Response.Write(Session("eKey") + " - 2 ")
            End If
        End If

        If Not Page.IsPostBack Then
            If Not Request.Cookies("syep") Is Nothing Then
                txtEmployerID.Text = Server.HtmlEncode(Request.Cookies("syep").Value)
            End If
        End If

    End Sub

    Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        'Cache("eKey") = txtEmployerID.Text
        'Cache("eTax") = txtTaxID.Text
        'Cache("wKey") = ""

        'Try using this to point to the connection string in the web.config.  Then it only needs to be changed in one place.
        'ConfigurationManager.ConnectionStrings["SYEP2007ConnectionString1"].ConnectionString

        'Dim Conn As New SqlConnection(ConfigurationManager.AppSettings("connectionstring"))
        'Dim DBConn As New SqlConnection("UID=dmegnin;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SYEP2007;Data Source=MSQLServ.broward-workforce.org;Packet Size=4096;")
        Dim DBConn As New SqlConnection(ConfigurationManager.ConnectionStrings("SYEP2007ConnectionString1").ConnectionString)
        'Dim DBConn As New SqlConnection("Integrated Security=SSPI;Initial Catalog=SYEP2007;Data Source=Windows7\SQLEXPRESS;")
        Dim SQLText As String
        SQLText = "SELECT txtEmployerName, txtCompanyStreet, txtCompanyCity,txtCompanyZip, txtContactContract, txtContactContractTitle, txtCompanyContractContactTelephone,txtCompanyContractContactFAX,txtCompanyContractContactCell, txtCompanyContractContactEmail FROM Employers WHERE (keyEmployerID = '" + txtEmployerID.Text + "') AND (txtFedID = '" + txtTaxID.Text + "')"
        Dim dr As SqlDataReader
        Dim DBCmd As SqlCommand = New SqlCommand(SQLText, DBConn)
        Try
            DBConn.Open()
            dr = DBCmd.ExecuteReader
            If dr.HasRows Then
                ' If Login good then pass eKey to the FormView on EmployerEdit1.aspx
                Session("eKey") = txtEmployerID.Text
                Session("eTax") = txtTaxID.Text
                'Response.Redirect("https://syep.wf1broward.com/EmployerEdit1.aspx")  'Restore this after City of Fort Lauderdale

                '' This put eKey and eTax into QueryString values to pass to the EmployerEdit1.aspx page.  I'll use Session Variable instead.
                'Start City of Fort Lauderdale........
                Dim url As String
                url = "EmployerEdit1.aspx?eKey=" + txtEmployerID.Text + _
                "&eTax=" + txtTaxID.Text
                Response.Redirect(url)
                'End City of Fort Lauderdale.....

                ''This is from Employer1.aspx.vb to verify login and pass variables.
                'While dr.Read()
                '    'Cache("eKey") = dr("keyEmployerID")
                '    Cache("eName") = dr("txtEmployerName")
                '    Cache("eAddress") = dr("txtCompanyStreet")
                '    Cache("eCity") = dr("txtCompanyCity")
                '    Cache("eZip") = dr("txtCompanyZip")
                '    Cache("cName") = dr("txtContactContract")
                '    Cache("cTitle") = dr("txtContactContractTitle")
                '    Cache("cPhone") = dr("txtCompanyContractContactTelephone")
                '    Cache("cFax") = dr("txtCompanyContractContactFAX")
                '    Cache("cCell") = dr("txtCompanyContractContactCell")
                '    Cache("cEmail") = dr("txtCompanyContractContactEmail")
                'End While
            Else
                lblLoginIncorrect.Text = "Login Incorrect"
                Exit Sub
            End If
        Catch exp As Exception
            Response.Write(exp)
        Finally
            DBCmd.Dispose()
            DBConn.Close()
            DBConn = Nothing
        End Try

        'Response.Write("eKey")
        'Response.Write("eTax")

    End Sub

    Protected Sub btnReturnToMain_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReturnToMain.Click
        Server.Transfer("default.htm")
    End Sub
End Class

Open in new window

Most Valuable Expert 2012
Top Expert 2014
Commented:
All your cookie related code is after this line at line 69

Response.Redirect(url)

which means any code after line 69 does not get executed.

Author

Commented:
Oh Crap!

That's why I love Experts-Exchange.  You catch stuff that I would overlook until the cows come home.

I'll move stuff about and try it again.  Duh.  ;-)

Author

Commented:
Doh!
It's amazing how things work when you aren't screwing the pooch.

Thank you very much.  Everything works as advertized now.  :-}
Most Valuable Expert 2012
Top Expert 2014

Commented:
Glad to help :-)