Scott
Scott

Reputation: 93

PreviousPage Findcontrol Issue

I need to get the text of the following linkbutton that is set to postback to another page:

<ItemTemplate>
     <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Bind("computername") %>' PostBackUrl="~/assetdetails.aspx" CommandName="Select">LinkButton</asp:LinkButton>
</ItemTemplate>

I have tried many things in the receiving pages load event but this is what i ended up with:

Dim GV As GridView = TryCast(PreviousPage.Master.FindControl("content").FindControl("GridView2"), GridView)
Dim LB As LinkButton = TryCast(GV.SelectedRow.Cells(0).FindControl("LinkButton1"), LinkButton)
lblAsset.Text = LB.Text

Obviously it doesnt (returns blank, not null) work or i would not be making this post. :) Please help!

Upvotes: 2

Views: 819

Answers (1)

R.C
R.C

Reputation: 10565

You are doing it wrong way.

Here GridView is inside a Content Page ( which uses a master page), so access the GridView present originally in content page as:

If (Not (Me.Page.PreviousPage) Is Nothing) Then
    Dim ContentPlaceHolder1 As Control =
                  Me.Page.PreviousPage.Master.FindControl("ContentPlaceHolder1")
    Dim GV As GridView =
                  CType(ContentPlaceHolder1.FindControl("GridView1"), GridView)

    Dim LB As LinkButton =
            TryCast(GV.SelectedRow.Cells(0).FindControl("LinkButton1"), LinkButton)
    lblAsset.Text = LB.Text
End If

GridView and other contents are present inside ContentPlaceHolder controls actually.

Upvotes: 1

Related Questions