?
Solved

How to utilize the CommandArgument value alongside PostBackUrl functionality??

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

771 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