Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a page (ASP.net) that contains two update panels, in the first one I add some controls in the run time (Textbox) and I want to get the values of these dynamically add controls in the second update panel upon the certain action in this panel.

If any one could advice with a proper solution for this situation taking in consideration that the two panels can't be merged in one update panel due to some business logic.

Thanks in advance :)
Posted

1 solution

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyEcommerce
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            btnShow.Attributes.Add("onclick", "show();");
        }

        protected void bntAdd_Click(object sender, EventArgs e)
        {
            TextBox txt = new TextBox();
            txt.ID = "txtMessage";
            NewUpdatePanel.Controls.Add(txt);
        }
    }
}


HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function show() {
            var txt = document.getElementById("txtMessage");
            var ans = document.getElementById("<%= txtAns.ClientID %>");
            ans.value = txt.value;          
        }
            
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <contenttemplate>
            <div id="NewUpdatePanel"  runat="server">
            </contenttemplate></div>
        
        
    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
        <contenttemplate>
            <div>
                <asp:Button ID="bntAdd" runat="server" Text="Add Control" 
                    onclick="bntAdd_Click" />
                    <asp:Button ID="btnShow" runat="server" Text="Show"/>
                <asp:TextBox ID="txtAns" runat="server" Text="">
            </div>
        </contenttemplate>
        
    
    </form>
</body>
</html>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900