我在updatepanel控件中的loginview里面有formview 和formview包含一个linkbutton.I必须注册链接按钮作为updatepanel触发器。
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="comments">
<h6>20 Diyo</h6>
<div class=" yorumat-div">
<asp:LoginView ID="loginYorumAtView" runat="server">
<LoggedInTemplate>
<asp:FormView ID="frmYorumAt" runat="server" DefaultMode="Insert" OnItemInserting="frmYorumAt_ItemInserting" DataSourceID="ods_YorumAt" >
<InsertItemTemplate>
<asp:TextBox ID="txtYorumAt" runat="server" CssClass="yorumat-txtbox" TextMode="MultiLine" Text='<%# Bind("Yorum_Text") %>'></asp:TextBox>
<asp:LinkButton ID="btnYorumAt" runat="server" CssClass="yorumat-button" CommandName="Insert" >Yolla</asp:LinkButton>
<asp:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" runat="server" TargetControlID="txtYorumAt" WatermarkText=" Yorum At ....">
</asp:TextBoxWatermarkExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" Display="None" ControlToValidate="txtYorumAt"></asp:RequiredFieldValidator>
</InsertItemTemplate>
</asp:FormView>
</LoggedInTemplate>
</asp:LoginView>
<asp:ObjectDataSource ID="ods_YorumAt" runat="server" InsertMethod="YorumEkle"
TypeName="yonet" DataObjectTypeName="Yorum"
oninserting="ods_YorumAt_Inserting" >
<InsertParameters>
<asp:QueryStringParameter DbType="Int32" Name="comment_post_idy" />
</InsertParameters>
</asp:ObjectDataSource>
</div>
<ul class="commentlist" >
<asp:DataList ID="datalistYorum" runat="server" DataSourceID="ods_yorumlar" ItemStyle-CssClass="commentlist" RepeatLayout="Table">
<ItemTemplate>
<li class="comment">
<div class="comment-body">
............<%# Eval("comment")%>...
</div>
</li>
</ItemTemplate>
</asp:DataList>
<asp:ObjectDataSource ID="ods_yorumlar" runat="server"
DataObjectTypeName="Yorum" TypeName="yonet" SelectMethod="PostYorumlariGetir"
ondatabinding="ods_yorumlar_DataBinding" onselecting="ods_yorumlar_Selecting">
<SelectParameters>
<asp:QueryStringParameter Name="comment_post_id" QueryStringField="post_id" Type="Int32" DefaultValue="2" />
</SelectParameters>
</asp:ObjectDataSource>
</ContentTemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>
和背后的代码
protected void Page_Load(object sender, EventArgs e)
{
//LinkButton btnYorumAt = loginYorumAtView.FindControl("frmYorumAt").FindControl("btnYorumAt") as LinkButton;
FormView frmYorumAt = (FormView)loginYorumAtView.FindControl("frmYorumAt");
LinkButton btnYorumAt = (LinkButton)frmYorumAt.FindControl("btnYorumAt");
ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(btnYorumAt);
}
错误:使用new关键字创建对象实例 很快就无法访问linkbutton 请帮助我 感谢
答案 0 :(得分:2)
由于FormView使用在绑定数据时填充的模板,因此您只能抓住DataBound事件的控件,如下所示:
protected void Page_Load(object sender, EventArgs e)
{
FormView frmYorumAt = (FormView)loginYorumAtView.FindControl("frmYorumAt");
frmYorumAt.DataBound += new EventHandler(frmYorumAt_DataBound);
}
void frmYorumAt_DataBound(object sender, EventArgs e)
{
FormView formView = sender as FormView;
// Let's make sure the InsertItemTemplate is actually being run, otherwise
// the LinkButton won't exist.
if (formView.CurrentMode == FormViewMode.Insert)
{
LinkButton btnYorumAt = (LinkButton)formView .FindControl("btnYorumAt");
// Do whatever you need to do with the LinkButton here.
}
}
答案 1 :(得分:0)