开发者

Cannot access the control id from a repeater's item template

开发者 https://www.devze.com 2023-02-10 09:16 出处:网络
Friends, I have a linkbutton inside a repeater\'s item templete and i want to access thelink buttons text on the next page.I set the postbackurl to the next page.But when i use the page.PrevoiusPage.

Friends, I have a linkbutton inside a repeater's item templete and i want to access the link buttons text on the next page.I set the postbackurl to the next page.But when i use the page.PrevoiusPage.Findcontrol("lnkReport") on the 开发者_如何学Godestination page's code behind , I get a null value .These are the markups .Can anyone please help?

<asp:Content ID="Content2" ContentPlaceHolderID="cpmain" runat="Server">

<fieldset id="fsTrialAct"></fieldset>

<asp:Repeater ID="rptRepeater" runat="server">

<asp:LinkButton ID="lnkReport" 
       PostBackUrl="~/features/Reports/AdHocReportDetail.aspx"
             runat="server"><%#Eval("AdhocBurstingReportName")%>
</asp:LinkButton></p>

</asp:Repeater>

</asp:Content>


You use master pages thus your repeater reside in Content Place Holder. What you need to do is find control of the Content Place Holder first before you find the repeater.

Example:

Control placeHolder = PreviousPage.Controls[0].FindControl("ContentPlaceHolder1");
TextBox SourceTextBox = (TextBox)placeHolder.FindControl("TextBox1");
if (SourceTextBox != null)
{
    Label1.Text = SourceTextBox.Text;
}

I assume in your case, instead of creating TextBox you should create repeater object and use FindControl again to find the link.

0

精彩评论

暂无评论...
验证码 换一张
取 消