Reputation: 93
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
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