Link to home
Start Free TrialLog in
Avatar of Srinivas Mantha
Srinivas ManthaFlag for India

asked on

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

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">
</asp:HyperLink>

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">
</asp:HyperLink>

Open in new window


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

Can anyone correct the syntax
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Srinivas Mantha

ASKER

Alternatively, one can use the following syntax which also works
<asp:TemplateField>
            <ItemTemplate>
                <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") %>'/>
            </ItemTemplate>
        </asp:TemplateField>

Please see the following link:

http://www.aspsnippets.com/Articles/How-to-bind-and-pass-query-string-in-HyperLink-in-GridView-in-ASPNet.aspx
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()));