Wednesday, August 19, 2009

Jquery--- checkbox check on/off display/hide some fields

I have one checkbox, I want to check on this checkbox display some textbox and lable, off check hide these textbox and lables, here is the function to do it:

$("#ckIsAgent").click(function() {
SwitchShowAgent();
});


function SwitchShowAgent() {
var ckValue = $("#ckIsAgent:checked").val();
if (ckValue)
ShowAgentData();
else
HideAgentData();
}
function HideAgentData() {

$("#lblAgentName").hide();
$("#txtAgentName").hide();
$("#lblAddress").hide();
$("#txtAddress").hide();
$("#lblSiteLink").hide();
$("#txtSiteLink").hide();
}
function ShowAgentData() {
$("#lblAgentName").show();
$("#txtAgentName").show();
$("#lblAddress").show();
$("#txtAddress").show();
$("#lblSiteLink").show();
$("#txtSiteLink").show();
}


the key part is using var ckValue = $("#ckIsAgent:checked").val(); to check the checked/not checked value

Saturday, August 1, 2009

.NET clear cookies

I try to clear my login cookies in .net by using Request.Cookies.clear(),
it doesn't work at all. Then I did some search online and found out set exired time to pass will solve this problem. I try and still not working, final I set the cookie value to empty string, works!
Notes: Request.Cookies.Clear() is a function to clear current buffer cookies. So confuse by MS.
here is code:

if (Request.Cookies != null && Request.Cookies.Count > 0)
{
foreach (string cookie in Request.Cookies.AllKeys)
{
Request.Cookies[cookie].Expires = DateTime.Now.AddDays(-1);
Response.Cookies[cookie].Value = "";

}

}
}