Click here to Skip to main content
14,870,616 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello People,

I have a data base containing 2 columns called Name and Contact. I want to store cookies in both the columns. Heres what i did :


DATASOURCE:
ASP
<asp:SqlDataSource ID="Sql1" runat="server" ConnectionString="<%$ ConnectionStrings:contacts %>" OnSelected="selected"  SelectCommand="select * from contacts" InsertCommand="insert contacts (Name,Contact) values(@Name,@Contact)"><insertparameters><asp:CookieParameter Name="Contact" CookieName="Contact" /><asp:CookieParameter Name="Name" CookieName="Name" /></insertparameters>

- I have used cookie parameters in insert parameters. which means when ever the page is requested then a cookie needs to be stored in the database in both columns.

FORMVIEW: ( take input from user)
ASP
<asp:FormView ID="fv" runat="server"   DefaultMode="Insert" DataSourceID="sql1"><insertitemtemplate><asp:Label ID="l1" Text="Vote for" runat="server"/><asp:RadioButtonList DataValueField='<%#Bind("Name")%>' ID="rbl"  runat="server"><asp:ListItem Text="Varinder" Value="Varinder" Selected="true" /><asp:ListItem Text="Santosh" Value="Santosh" /> <asp:Button ID="b1" Text="Submit" runat="server" CommandName="Insert" />  </insertitemtemplate>

- I have used a form view for the user to input. I have just tried to implement a voting sort of a mechanism in which when a radio button is selected and a button is pressed, then a cookie will be stored against that person's entry in the database.

The code behind is :
C#
protected void Page_Load(object sender, EventArgs e)
      {
          if(Request.Cookies["Name"]==null)
          {
              string identifier = Guid.NewGuid().ToString();
              HttpCookie namecoockie = new HttpCookie("Name",identifier);
              namecoockie.Expires = DateTime.MaxValue;
              Response.AppendCookie(namecoockie);


          }
      }

- What i wanted to do is that when ever user selects a radio button then a cookie corresponding to that radio button selection will be stored into the data base.
- I am successfull in it, but the catch is that my cookie is being duplicated in only column, where as i want the entry of the cookie in both Name and Contact column.
- My doubt is that the cookie is of type string. The "Name" column of my database is also of type string, but "Contact" column is of type int.
- Is this the reason? Because in the insert parameter i have clearly specified what to insert where.


Thanks,
Posted
Updated 29-Aug-13 0:44am
v2
Comments
Mahesh Bailwal 29-Aug-13 11:57am
   
where you are setting value for Contact cookie in code?
Rahul VB 29-Aug-13 15:25pm
   
Respected sir,

I tried doing something like this :

if((Request.Cookies["Name"]==null)&&(Request.Cookies["Contact"]==null))
{
string identifier1 = Guid.NewGuid().ToString();
string identifier2 = Guid.NewGuid().ToString();
HttpCookie namecoockie = new HttpCookie("Name",identifier1);
HttpCookie contactcoockie = new HttpCookie("Contact",identifier2);

namecoockie.Expires = DateTime.MaxValue;
contactcoockie.Expires = DateTime.MaxValue;

Response.AppendCookie(namecoockie);
Response.AppendCookie(contactcookie);

}
- According to this what i feel is that during the first response it will send these cookies one after another and then it does not add these cookies in two seperate columns but in the same columns one below the other.

- Please advise

Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900