Solved

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

Posted on 2014-03-18
2
1,946 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now