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"
onclic开发者_开发问答k="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?!
You need to invoke Update()
method after the content of UpdatePanel
is modified by the postback event handlers.
精彩评论