我在更新面板内的客户端上有一个动态控件和一个文本框,它从数据库中读取数据
<asp:DynamicControl ID="text1" runat="server" Text='<%# Eval("image_path") %>' DataField="image_path" Mode="Edit" ClientIDMode="Static" UIHint="MultilineText" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
单击按钮时,它应该从动态控件中获取值并显示在文本框中
服务器端
protected void Button1_Click(object sender, EventArgs e)
{
DynamicControl tb1 = (DynamicControl)FormView1.FindControl("text1");
TextBox tb2 = (TextBox)FormView1.FindControl("TextBox1");
tb1.DataField = tb2.Text; // here I need to display the value of dynamic control in Textbox but
its not shown
// I tried this as well
TextBox linkText = new TextBox();
linkText.ID = "txtLink";
linkText.Text = tb1.DataField; //here also I tried to retrieve the value but unable
linkText.ClientIDMode = System.Web.UI.ClientIDMode.Static;
tb1.Controls.Add(linkText);
}
还尝试了 UpdatePanel1.Update();
注意:Button1 在更新面板之外
请需要解决方案
更新客户端代码
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
HeaderText="List of validation errors" CssClass="DDValidator" />
<asp:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="FormView1" Display="None" CssClass="DDValidator" />
<asp:FormView runat="server" ID="FormView1" DataSourceID="DetailsDataSource" DefaultMode="Edit"
OnItemCommand="FormView1_ItemCommand" OnItemUpdated="FormView1_ItemUpdated" RenderOuterTable="false">
<EditItemTemplate>
<table id="detailsTable" class="DDDetailsTable" cellpadding="6">
<asp:DynamicEntity runat="server" Mode="Edit" />
<tr class="td">
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td>
<asp:DynamicControl ID="text1" runat="server" DataField="image_path" Mode="Edit" ClientIDMode="Static" UIHint="MultilineText" />
</td>
<td colspan="2">
<asp:LinkButton runat="server" CommandName="Update" Text="Update" />
<asp:LinkButton runat="server" CommandName="Cancel" Text="Cancel" CausesValidation="false" />
</td>
</tr>
</table>
</EditItemTemplate>
<EmptyDataTemplate>
<div class="DDNoItem">No such item.</div>
</EmptyDataTemplate>
</asp:FormView>
<asp:LinqDataSource ID="DetailsDataSource" runat="server" EnableUpdate="true" />
<asp:QueryExtender TargetControlID="DetailsDataSource" ID="DetailsQueryExtender" runat="server">
<asp:DynamicRouteExpression />
</asp:QueryExtender>
</ContentTemplate>
</asp:UpdatePanel>