Pass value from one page to another using Cookies in ASP.Net

Last Reply 8 months ago By dharmendr

Posted 8 months ago

There is an example:

Here value is passing using sessionStorage, then showing in aspx file. It's useful.

But I want to assign cardno value to string type variable, like:

string cn=1111234567123456;

"cn" will be used in cs code.



Posted 8 months ago Modified on 8 months ago

Hi Alauddin,

To pass data from one page to another use cookie. Cookie will save the value. Then retrieve the value from cookie in page load and display in label.

Note: This method will work only if Cookies are enabled in browser.

For more details refer below article.

Send (Pass) Data (Values) from one page to another using jQuery


<asp:Label ID="lblTable" runat="server"></asp:Label>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
    window.onload = function () {
        var table = document.getElementsByTagName("table");
        var trs = table[0].getElementsByTagName('tr');
        for (var i = 0; i < trs.length; i++) {
            var tds = trs[i].getElementsByTagName('td');
            var cardno = tds[1].innerText;
            if (cardno.length > 5) {
                var firstFour = cardno.substr(0, 4);
                var lastFour = cardno.substr(cardno.length - 4, cardno.length);
                var middle = cardno.substr(4, cardno.length - 8).replace(/[0-9]/g, "*");
                var newLink = document.createElement("a");
                newLink.setAttribute("href", "Default.aspx");
                newLink.setAttribute("onclick", 'return CardNumber("' + cardno + '")');
                text = document.createTextNode(firstFour + middle + lastFour);
                tds[1].innerHTML = "";
    function CardNumber(cardno) {
        $.cookie("cardNumber", cardno);


protected void Page_Load(object sender, EventArgs e)
    if (!this.IsPostBack)
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("<table id='01717458720_CardList'>");
        sb.Append("<td id='product_type'>CREDIT CARD</td>");
        sb.Append("<td id='card_no' abbr='*'>1111234567123456</td>");
        sb.Append("<td id='card_status'>INACTIVE</td>");
        sb.Append("<td id='acct_no'>N/A</td>");
        sb.Append("<td id='name'>Mr. X</td>");
        sb.Append("<td id='product_type'>DEBIT CARD</td>");
        sb.Append("<td id='card_no'>0000000000000000</td>");
        sb.Append("<td id='card_status'>ACTIVE</td>");
        sb.Append("<td id='acct_no'>55555555555</td>");
        sb.Append("<td id='name'>Mrs. Y</td>");
        lblTable.Text = sb.ToString();


<asp:Label ID="lblCardNo" runat="server" />


protected void Page_Load(object sender, EventArgs e)
    if (!IsPostBack)
        lblCardNo.Text = Request.Cookies["cardNumber"].Value;