Solved

How to utilize the CommandArgument value alongside PostBackUrl functionality??

Posted on 2006-06-22
6
1,425 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

709 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

13 Experts available now in Live!

Get 1:1 Help Now