?
Solved

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

Posted on 2014-03-18
2
Medium Priority
?
2,098 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:Srinivas Mantha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

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

Open in new window

0
 

Author Closing Comment

by:Srinivas Mantha
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

719 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