只能在 updatepanel 中添加有限的动态用户控件
抱歉我的语言问题:D
我已经编写了下面的代码,对此没有任何问题,但我可以动态添加 6 个以上的用户控件(DriverInfo.ascx
)。
我尝试过使用单个文本框而不是用户控件的更简单的代码,但它不适用于超过 30 个文本框。我不知道出了什么问题并且很困惑。问题是什么?
AddDynamicDriver.ascx:
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="AddDynamicDirver.ascx.cs"
Inherits="Terminal.UI.TransportCo.WebControls.AddDynamicDirver" %>
<div dir="rtl">
<asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="Panelmain" runat="server">
</asp:Panel>
<asp:Button ID="AddDriver" runat="server" Text="adddriver"
onclick="AddDriver_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
addDynamicDriver.ascx.cs:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["DynamicDriverNumber"] = 1;
LoadCreatedControl();
}
}
private void LoadCreatedControl()
{
var number = (int)Session["DynamicDriverNumber"];
for (int i = 1; i <= number; i++)
{
var driver = new Control();
driver = LoadControl("DriverInfo.ascx");
driver.ID = "Driver" + i;
Panelmain.Controls.Add(driver);
Panelmain.Controls.Add(new LiteralControl("<hr/>"));
}
public void AddDriver_Click(object sender, EventArgs e)
{
var number = (int)Session["DynamicDriverNumber"];
number++;
Session["DynamicDriverNumber"] = number;
LoadCreatedControl();
}
这是一个 Firefox 问题,因为它在 IE 中工作。为什么?!
Sorry for my language problem :D
I've written below code and I have no problem with that but I can add more than 6 user control(DriverInfo.ascx
) dynamically.
I've tried a simpler code with a single textbox instead of user control but it does not work for more than 30 textbox. I don't know whats the problem and got confused. what is the problem?
AddDynamicDriver.ascx:
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="AddDynamicDirver.ascx.cs"
Inherits="Terminal.UI.TransportCo.WebControls.AddDynamicDirver" %>
<div dir="rtl">
<asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="Panelmain" runat="server">
</asp:Panel>
<asp:Button ID="AddDriver" runat="server" Text="adddriver"
onclick="AddDriver_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
addDynamicDriver.ascx.cs:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["DynamicDriverNumber"] = 1;
LoadCreatedControl();
}
}
private void LoadCreatedControl()
{
var number = (int)Session["DynamicDriverNumber"];
for (int i = 1; i <= number; i++)
{
var driver = new Control();
driver = LoadControl("DriverInfo.ascx");
driver.ID = "Driver" + i;
Panelmain.Controls.Add(driver);
Panelmain.Controls.Add(new LiteralControl("<hr/>"));
}
public void AddDriver_Click(object sender, EventArgs e)
{
var number = (int)Session["DynamicDriverNumber"];
number++;
Session["DynamicDriverNumber"] = number;
LoadCreatedControl();
}
It's a Firefox problem as it works in IE. Why?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在回发事件处理程序修改
UpdatePanel
的内容后,您需要调用Update()
方法。You need to invoke
Update()
method after the content ofUpdatePanel
is modified by the postback event handlers.