I'm trying to add controls dynamically
Code:
AddVisaControl.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AddVisaControl.ascx.cs" EnableViewState="false" Inherits="Pyramid.AddVisaControl" %>
<%@ Register assembly="BasicFrame.WebControls.BasicDatePicker" namespace="BasicFrame.WebControls" tagprefix="BDP" %>
<div id="divreg" runat="server">
<table id="tbl" runat="server">
<tr>
<td class="style8"> Visa Number:</td>
<td class="style20"><asp:TextBox ID="txtUser" Width="160px" runat="server"/></td>
<td class="style22"> Country Name:</td>
<td class="style23">
<asp:DropDownList ID="dropCountry" Width="165px" runat="server">
</asp:DropDownList></td>
</tr>
<tr>
<td class="style22"> Type of Visa:</td>
<td class="style23">
<asp:DropDownList ID="dropVisa" Width="165px" runat="server"> </asp:DropDownList></td>
<td class="style22"> Type of Entry:</td>
<td class="style23">
<asp:DropDownList ID="dropEntry" Width="165px" runat="server"> </asp:DropDownList></td>
</tr>
<tr>
<td class="style8"> Expiry Date</td>
<td class="style20">
</td>
</tr>
</table>
.cs code:
Below code is the problem when the first time I click add button it is adding controls properly but If I close the browser window and comes again and click the add button I got more controls
static int i = 0;
protected void addnewtext_Click(object sender, EventArgs e)
{
i++;
for (int j = 0; j <= i; j++)
{
AddVisaControl ac = (AddVisaControl)Page.LoadControl("AddVisaControl.ascx");
PlaceHolder1.Controls.Add(ac);
PlaceHolder1.Controls.Add(new LiteralControl("<BR>"));
}
}
In the below image If I click add more visa button I want to get another visa details
Any ideas? Thanks in advance
See Question&Answers more detail:os