Solved

How to utilize the CommandArgument value alongside PostBackUrl functionality??

Posted on 2006-06-22
6
1,431 Views
Last Modified: 2012-05-05
I have a gridview that displays a list of links.  Each link has a commandArgument (pulled from the database), like so...

<ItemTemplate>
   <asp:linkbutton runat="server" ID="lnk" Text="Click to View" PostBackUrl="~/page2.aspx" CommandArgument='<%# Eval("ID") %>' />
</ItemTemplate>

I'd like the link to post to a new page (page2.aspx), but yet still have access to the link's commandArgument value in the destination page.  

Is this possible??

I've tried both queryString and Session to pass the value across to page2, but each seem to have their weaknesses.
I know I can use PreviousPage.FindControl in a normal non-gridview situation, but how does it work is this instance??
0
Comment
Question by:Rouchie
  • 2
  • 2
6 Comments
 
LVL 5

Expert Comment

by:Argblat
ID: 16959815
Try this:

Get rid of the PostBackUrl attribute, and add an onCommand event to the GridView.  In the code behind for this event, add something like Response.Redirect("~/page2.aspx" + e.CommandArgument

It's not going to look exactly like that I don't think, but the idea just might get you what you need.

-Mike
0
 
LVL 25

Author Comment

by:Rouchie
ID: 16959897
This forms a URL such as this when the links are clicked:
   http://localhost/solution/page2.aspx6

Previously today I amended the redirection code to say this:
  Response.Redirect("page2.aspx?id=" & e.CommandArgument, True)
which gave a correctly formatted URL, but as I mentioned in the question I want to stay away from querystrings.  This is mainly to hide this sort of stuff from the user.
0
 
LVL 5

Expert Comment

by:Argblat
ID: 16960816
Is the issue passing the data to the next page, or the way you pass the data to the next page?

You should be aware of the pro's and con's of all the ways that you can pass data from one page to another (querystring, session, etc), weigh your options, and choose the one that's right for the situation.

It was my understanding that the question at hand was how to grab the information to be passed, and that once we accomplished this you could do the analysis and decision making on how to pass the data yourself ... Correct me if I am wrong about this...

Getting the '6' at the end of the querystring accomplished the first task. . . my apologies for forgetting the '?id=' part, but you seem to have figured that out on your own

What is there left to do?

-Mike
0
 
LVL 25

Author Comment

by:Rouchie
ID: 16960993
Hi Mike
The problem is the 'way' in which the data is passed.  I know of a few approaches that work that I have tried already:

 1) Querystring - looks untidy and allows for abuse
 2) Session - Works well but I clear out the session once the value is read back in on page2.  This results in errors if page2 is refereshed as the session is cleared.
                   Currently I am using this approach and redirecting back to page1 if the session value is not found
 3) Javascript to populate hidden text box prior to submitting - Lots more work!
 4) Server.Transfer - probably the best I guess but will get confusing if errors creep in!

I had hoped (given the popularity of the gridview) that there'd be an easy way to pass the data under the hood to page2.  That's why I wondered about CommandArgument given that it plays a vital role in all the other approaches.  After reading about this all day though it seems a waste of time because if there was 100 rows in the view, then you'd need to differentiate them.  

Perhaps I'm just looking for something that's over-complicated...!   8-/
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 17105712
Closed, 500 points refunded.
Netminder
Site Admin
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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