How to encrypt multiple query string values passing from gridview in asp.net?

Posted on 2014-03-18
Medium Priority
Last Modified: 2014-03-19
The following syntax to encrypt single query string value passing from gridview in asp.net is working properly

<asp:HyperLink ID="HyperLink1" NavigateURL='<%# "billingitemsentrylab.aspx?pid=" + HttpUtility.UrlEncode(EncDecMK.Encrypt(Eval("pid").ToString())) %>' Text='<%# Eval("pname") %>' runat= "server">

Open in new window

However the following syntax to encrypt multiple query string values from gridview is not working.

<asp:HyperLink ID="HyperLink1" NavigateURL='<%# "adminpatientlabinfo.aspx?pid=" + HttpUtility.UrlEncode(EncDecMK.Encrypt(Eval("pid").ToString()))+ "&rnumber=" HttpUtility.UrlEncode(EncDecMK.Encrypt(Eval("rnumber").ToString())) + "&financialyear=" HttpUtility.UrlEncode(EncDecMK.Encrypt(Eval("financialyear").ToString()))  %>' Text='<%# Eval("pname") %>' runat= "server">

Open in new window

All parameter values i.e. pid, rnumber and financial year are integers

Can anyone correct the syntax
Question by:Srinivas Mantha
LVL 35

Accepted Solution

Robert Schutt earned 2000 total points
ID: 39939136
It seems to me you're just missing a few + signs:
<asp:HyperLink ID="HyperLink1" NavigateURL='<%# "adminpatientlabinfo.aspx?pid=" + HttpUtility.UrlEncode(EncDecMK.Encrypt(Eval("pid").ToString())) + "&rnumber=" + HttpUtility.UrlEncode(EncDecMK.Encrypt(Eval("rnumber").ToString())) + "&financialyear=" + HttpUtility.UrlEncode(EncDecMK.Encrypt(Eval("financialyear").ToString()))  %>' Text='<%# Eval("pname") %>' runat= "server">

Open in new window


Author Closing Comment

by:Srinivas Mantha
ID: 39939230
Alternatively, one can use the following syntax which also works
                <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# string.Format("adminpatientlabinfo.aspx?pid={0}&rnumber={1}&financialyear={2}",
                    HttpUtility.UrlEncode(EncDecMK.Encrypt(Eval("pid").ToString())), HttpUtility.UrlEncode(EncDecMK.Encrypt(Eval("rnumber").ToString())), HttpUtility.UrlEncode(EncDecMK.Encrypt(Eval("financialyear").ToString()))) %>'
                    Text='<%# Eval("pname") %>'/>

Please see the following link:

The above reference uses encryption and decryption code on every page. Instead, in my project i have written the code in separate C# class file and used it where necessary
For example, on aspx page where the gridview is located, I used
<%@ Import Namespace="EncryptDecryptMK" %>
And in the destination (target), aspx.cs code file I used
using EncryptDecryptMK;

lblpid.Text = EncDecMK.Decrypt(HttpUtility.UrlDecode(Request.QueryString["pid"].ToString()));
        lblrnumber.Text = EncDecMK.Decrypt(HttpUtility.UrlDecode(Request.QueryString["rnumber"].ToString()));

       lblfyear.Text = EncDecMK.Decrypt(HttpUtility.UrlDecode(Request.QueryString["financialyear"].ToString()));

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

There is a wide range of advantages associated with the use of ASP.NET. This is why this programming framework is used to create excellent enterprise-class websites, technologies, and web applications.
The PowerShell Core 6.0 of .NET release is just the beginning. The upcoming PowerShell Core 6.1 would have artificial intelligence and internet of things capabilities. So many things to look forward to in the upcoming release.
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Watch the video to know the simple way to remove or recover or reset lost or forgotten passwords of Outlook PST file. With Kernel Outlook Password Recovery tool such operation is very easy to perform. It is a freeware with limitation to use with 500…

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question