Setting a cookie in ASP.net based on a drop down list

I'm taking my first attempt at setting a cookie in ASP.net. I have a drop down list that lists all users of the application. Once the user has made their selection from the drop down list, they have the option of clicking a checkbox. When they click the checkbox, I would like for the value of the dropdownlist to be saved as a cookie. I would like to use that value to set the default value of the drop down list. I'm not sure what kind of event to put my code in or even if the code is correct. I've pasted it below. Thank you for your help.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then Dim s As String = Response.Cookies("PipelineCookie")("DefaultOfficer") If Not String.IsNullOrEmpty(s) Then DropDownList1.SelectedValue = s End If End If End Sub Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged Response.Cookies("PipelineCookie")("DefaultOfficer") = DropDownList1.SelectedValue End Sub

sorry my vb sucks, try this.
you could set autopostback = true on your dropdown
you may also want to control the cookie expiration a little better...

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then Dim cook As HttpCookie = Request.Cookies("PipelineCookie") If Not cook Is Nothing Then Dim s As String = cook("DefaultOfficer") If Not String.IsNullOrEmpty(s) Then DropDownList1.SelectedValue = s End If End If End If End Sub Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged Response.Cookies("PipelineCookie")("DefaultOfficer") = DropDownList1.SelectedValue End Sub

Featured Post

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB.
To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…