Hello..
Here is my HTML Code
<%@ Page Title="" Language="C#" MasterPageFile="~/Layout/FrontPage.master" AutoEventWireup="true" CodeFile="BussinessReg.aspx.cs" Inherits="UserForm_BussinessReg" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<asp:PlaceHolder ID="myPlaceHolder" runat="server"></asp:PlaceHolder>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="btnAdd" runat="server" Text="AddNew" onclick="btnAdd_Click" UseSubmitBehavior="true" />
</td>
Here is my C# Code
protected void Page_PreInit(object sender, EventArgs e) { Control myControl = GetPostBackControl(this.Page);
if ((myControl != null))
{
if ((myControl.ClientID.ToString() == "AddNew"))
{
myCount = myCount + 1;
}
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
dynamicTextBoxes = new TextBox[myCount];
int i;
for (i = 0; i < myCount; i += 1)
{
TextBox textBox = new TextBox();
textBox.ID = "myTextBox" + i.ToString();
myPlaceHolder.Controls.Add(textBox);
dynamicTextBoxes[i] = textBox;
LiteralControl literalBreak = new LiteralControl("<br />");
myPlaceHolder.Controls.Add(literalBreak);
}
}
public static Control GetPostBackControl(Page thePage)
{
Control myControl = null;
string ctrlName = thePage.Request.Params.Get("__EVENTTARGET");
if (((ctrlName != null) & (ctrlName != string.Empty)))
{
myControl = thePage.FindControl(ctrlName);
}
else
{
try
{
foreach (string Item in thePage.Request.Form)
{
Control c = ((ContentPlaceHolder)thePage.Master.FindControl("ContentPlaceHolder1")).Page.FindControl(Item);
//Here I Not geeting the control Which it in Item
if (((c) is System.Web.UI.WebControls.Button))
{
myControl = c;
}
}
}
catch (Exception ex)
{
string msg = ex.Message;
}
}
return myControl;
}
Here I am using the code in a content page...
For Simple page without master page works fine but even though textbox control are getting located but the button which causes the postback is not getting located.
Please help