Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to utilize the CommandArgument value alongside PostBackUrl functionality??

Posted on 2006-06-22
6
Medium Priority
?
1,448 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
[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
  • 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

609 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