如何在文本框中添加asp:动态控件值

时间:2021-03-01 08:35:43

标签: c# asp.net server-side dynamic-data-site

我在更新面板内的客户端有动态控件和文本框,可以从数据库中读取数据

 <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>


0 个答案:

没有答案