Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > LinkButton : How to navigate to a child in another page

Reply
Thread Tools

LinkButton : How to navigate to a child in another page

 
 
Bazza Formez
Guest
Posts: n/a
 
      12-19-2004
Hi,

The intended functionality is as follows :

I want the user to be able to click on the LinkButton for an individual row
in a datagrid, server side sub grabs id for item selected, stores in session
& reirects user to new page which retrieves id from session & loads its own
grid accordingly.

Note that I don't want pass info as a parameter tacked on to the url... and
this is why I am not using a hyperlink.

My question(s) are :
(1) what is the syntax in the html to build the template column properly for
the LinkButon to acheive this.
(2) How do I tie this in the server side code and retrieve the item
selected.
(3) Also, Am I doing this the hard way. Is there a better way to pass data &
still avoid user seeing parameters ?

Thanks !

Bazza


 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      12-19-2004
"Bazza Formez" <(E-Mail Removed)> wrote in message
news:41c5faf4$(E-Mail Removed)...
> Hi,
>
> The intended functionality is as follows :
>
> I want the user to be able to click on the LinkButton for an individual
> row in a datagrid, server side sub grabs id for item selected, stores in
> session & reirects user to new page which retrieves id from session &
> loads its own grid accordingly.
>
> Note that I don't want pass info as a parameter tacked on to the url...
> and this is why I am not using a hyperlink.
>
> My question(s) are :
> (1) what is the syntax in the html to build the template column properly
> for the LinkButon to acheive this.
> (2) How do I tie this in the server side code and retrieve the item
> selected.
> (3) Also, Am I doing this the hard way. Is there a better way to pass data
> & still avoid user seeing parameters ?


1) On one of my forms, I have the following:

<asp:TemplateColumn HeaderText="Buy?"><ItemTemplate>
<asp:LinkButton ID="lnkToShopFor" Runat="server"
CommandName="Toggle">No</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>

This renders as:

<td>
<a id="grdShoppingList_ctl02_lnkToShopFor"
href="javascript:__doPostBack('grdShoppingList$ctl 02$lnkToShopFor','')">No</a>
</td>

2) On the server side, you pick this up in the ItemCommand event of the data
grid. The EventArgs will pass you the DataGridItem which represents this row
in the grid, in the Item property. It will also pass you the CommandName and
CommandArgument properties from the LinkButton. If the ID you want to pass
in Session is the primary key of the DataTable you bound the grid to, and if
you specified the DataKey property of the DataGrid, then the grids DataKeys
property can be indexed by e.Item.ItemIndex to find the primary key for that
row. Otherwise, you can pass the id in the CommandArgument property through
data binding.

3) This it the better way. At base, it stores the values in hidden input
fields and then posts back. The receiving control (in this case, the
LinkButton) raises a PostBack event based on the values it finds in the
hidden fields. The event handler then deals with the event, or, in this
case, bubbles it up to its enclosing control (the DataGrid), for you to
handle in the ItemCommand event.

BTW, the other way to not pass parameters is for the client-side code to set
a cookie, but that's not pretty. The hidden form field method is better, and
letting the LinkButton and DataGrid do it for you is better still!

John Saunders


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MasterPage - ContentPlaceHolder - How to navigate to the ContentPlaceHolder "Child Page" Greg ASP .Net 4 04-17-2006 03:48 PM
MasterPage - ContentPlaceHolder - How to navigate to the ContentPlaceHolder "Child Page" Greg ASP .Net Web Controls 1 03-23-2006 10:17 AM
Linkbutton does not look like a linkbutton Sathyaish ASP .Net 3 09-08-2005 09:41 AM
Linkbutton does not look like a linkbutton Sathyaish ASP .Net Datagrid Control 1 09-08-2005 08:44 AM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments