Solved

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

Posted on 2014-03-18
2
1,989 Views
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">
</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
0
Comment
Question by:smanthanims
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 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">
</asp:HyperLink>

Open in new window

0
 

Author Closing Comment

by:smanthanims
ID: 39939230
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()));
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

810 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