LinkButton : How to navigate to a child in another page

Discussion in 'ASP .Net' started by Bazza Formez, Dec 19, 2004.

  1. Bazza Formez

    Bazza Formez Guest

    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
     
    Bazza Formez, Dec 19, 2004
    #1
    1. Advertising

  2. "Bazza Formez" <> wrote in message
    news:41c5faf4$...
    > 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$ctl02$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
     
    John Saunders, Dec 19, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sathyaish
    Replies:
    3
    Views:
    3,168
    Sathyaish
    Sep 8, 2005
  2. Greg
    Replies:
    4
    Views:
    14,938
    dassyms
    Apr 17, 2006
  3. Jeff Rodriguez
    Replies:
    23
    Views:
    1,200
    David Schwartz
    Dec 9, 2003
  4. Sathyaish

    Linkbutton does not look like a linkbutton

    Sathyaish, Sep 8, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    215
    Sathyaish
    Sep 8, 2005
  5. Greg
    Replies:
    1
    Views:
    227
    Ward Bekker
    Mar 23, 2006
Loading...

Share This Page