从在另一个“更新"面板中动态添加的控件中获取更新面板中的值 [英] Get values in an update panel from controls added dynamically in another Update panel
本文介绍了从在另一个“更新"面板中动态添加的控件中获取更新面板中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个页面(ASP.net),其中包含两个更新面板,在第一个页面中,我在运行时(文本框)添加了一些控件,并且我想在第二个更新面板中获取这些动态添加控件的值.根据此面板中的特定操作.
考虑到由于某种业务逻辑而无法将两个面板合并到一个更新面板中,如果有人可以针对这种情况提出适当的解决方案的建议.
在此先感谢:)
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 :)
推荐答案
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 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>
这篇关于从在另一个“更新"面板中动态添加的控件中获取更新面板中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文