problem whil adding user control dynamically multiple times

P

parulrgupta

I have two buttons add and save on my aspx page

as and when i click on save button ,i want to load user control on form
it works fine but when i click on add button then that previously
loadded user contol goes away

i dont kow why this happnes ...

if anybody have any idea abt it then plz help me


code is

protected void btnProfessionalAdd_Click(object sender,
ImageClickEventArgs e)
{
txtProject.ReadOnly = false;
txtLocation.ReadOnly = false;
txtCompany.ReadOnly = false;
txtEnvironment.ReadOnly = false;
txtDescription.ReadOnly = false;
txtDuration.ReadOnly = false;
//LoadNewControl();


}

protected void btnProfessionalSave_Click(object sender,
ImageClickEventArgs e)
{
//DataSet DS;
SqlParameter ParamCompany=new
SqlParameter("@Company",SqlDbType.VarChar,50);
ParamCompany.Value=txtCompany.Text;
SqlParameter ParamLocation=new
SqlParameter("@Location",SqlDbType.VarChar,50);
ParamLocation.Value=txtLocation.Text;
SqlParameter ParamPeriod=new
SqlParameter("@Period",SqlDbType.VarChar,20);
ParamPeriod.Value=txtDuration.Text;
SqlParameter ParamProject=new
SqlParameter("@project",SqlDbType.VarChar,50);
ParamProject.Value=txtProject.Text;
SqlParameter ParamDesc=new
SqlParameter("@ProjectDescription",SqlDbType.VarChar,5000);
ParamDesc.Value=txtDescription.Text;
SqlParameter ParamTech=new
SqlParameter("@Technology",SqlDbType.VarChar,1000);
ParamTech.Value=txtEnvironment.Text;
SqlParameter ParamResumeID=new
SqlParameter("@ResumeId",SqlDbType.VarChar,50);
ParamResumeID.Value = "(e-mail address removed)";
//Session["ERResumeID"].ToString();

SqlHelper.ExecuteNonQuery(CommonClass.GetConnectionString(),CommandType.StoredProcedure,"spInsertEmployeeExperience",ParamCompany,ParamLocation,ParamPeriod,ParamProject,ParamDesc,ParamTech,ParamResumeID);

ClearFields();
LoadNewControl();



}
protected void ClearFields()
{
txtProject.Text = "";
txtLocation.Text= "";
txtCompany.Text = "";
txtEnvironment.Text = "";
txtDescription.Text = "";
txtDuration.Text = "";
txtProject.ReadOnly = true;
txtLocation.ReadOnly = true;
txtCompany.ReadOnly = true;
txtEnvironment.ReadOnly = true;
txtDescription.ReadOnly = true;
txtDuration.ReadOnly = true;
}
protected void LoadNewControl()
{
Control myCnt;
int cnt=0;
int i;
cnt++;
if (hiddnCnt.Value == "")
{
cnt = cnt;
}
else
{
cnt = Convert.ToInt32(hiddnCnt.Value) +1;
//cnt=cnt+1;
}
//cntName As New Control()
//cntName.ID = "PlaceHolder" & cnt
//form1.Controls.Add(cntName)
for(i=0;i<=cnt-1;i++)
{
myCnt = LoadControl("Project.ascx");
myCnt.ID = "Control" +i;
// Panel1.Controls.Add(myCnt);
form1.Controls.Add(myCnt);

}
hiddnCnt.Value = cnt.ToString();

}
 
A

Alessandro Zifiglio

hi, keep looking in old posts within this group. It has come up on various
occassions and you will find some very good answers. Basically as a rule of
thumb, keep in mind that any controls you add to the webform dynamically
need to be reloaded manually by yourself(the same way it was loaded the last
time) after a postback scenario.

Have a good day,
Alessandro Zifiglio
I have two buttons add and save on my aspx page

as and when i click on save button ,i want to load user control on form
it works fine but when i click on add button then that previously
loadded user contol goes away

i dont kow why this happnes ...

if anybody have any idea abt it then plz help me


code is

protected void btnProfessionalAdd_Click(object sender,
ImageClickEventArgs e)
{
txtProject.ReadOnly = false;
txtLocation.ReadOnly = false;
txtCompany.ReadOnly = false;
txtEnvironment.ReadOnly = false;
txtDescription.ReadOnly = false;
txtDuration.ReadOnly = false;
//LoadNewControl();


}

protected void btnProfessionalSave_Click(object sender,
ImageClickEventArgs e)
{
//DataSet DS;
SqlParameter ParamCompany=new
SqlParameter("@Company",SqlDbType.VarChar,50);
ParamCompany.Value=txtCompany.Text;
SqlParameter ParamLocation=new
SqlParameter("@Location",SqlDbType.VarChar,50);
ParamLocation.Value=txtLocation.Text;
SqlParameter ParamPeriod=new
SqlParameter("@Period",SqlDbType.VarChar,20);
ParamPeriod.Value=txtDuration.Text;
SqlParameter ParamProject=new
SqlParameter("@Project",SqlDbType.VarChar,50);
ParamProject.Value=txtProject.Text;
SqlParameter ParamDesc=new
SqlParameter("@ProjectDescription",SqlDbType.VarChar,5000);
ParamDesc.Value=txtDescription.Text;
SqlParameter ParamTech=new
SqlParameter("@Technology",SqlDbType.VarChar,1000);
ParamTech.Value=txtEnvironment.Text;
SqlParameter ParamResumeID=new
SqlParameter("@ResumeId",SqlDbType.VarChar,50);
ParamResumeID.Value = "(e-mail address removed)";
//Session["ERResumeID"].ToString();

SqlHelper.ExecuteNonQuery(CommonClass.GetConnectionString(),CommandType.StoredProcedure,"spInsertEmployeeExperience",ParamCompany,ParamLocation,ParamPeriod,ParamProject,ParamDesc,ParamTech,ParamResumeID);

ClearFields();
LoadNewControl();



}
protected void ClearFields()
{
txtProject.Text = "";
txtLocation.Text= "";
txtCompany.Text = "";
txtEnvironment.Text = "";
txtDescription.Text = "";
txtDuration.Text = "";
txtProject.ReadOnly = true;
txtLocation.ReadOnly = true;
txtCompany.ReadOnly = true;
txtEnvironment.ReadOnly = true;
txtDescription.ReadOnly = true;
txtDuration.ReadOnly = true;
}
protected void LoadNewControl()
{
Control myCnt;
int cnt=0;
int i;
cnt++;
if (hiddnCnt.Value == "")
{
cnt = cnt;
}
else
{
cnt = Convert.ToInt32(hiddnCnt.Value) +1;
//cnt=cnt+1;
}
//cntName As New Control()
//cntName.ID = "PlaceHolder" & cnt
//form1.Controls.Add(cntName)
for(i=0;i<=cnt-1;i++)
{
myCnt = LoadControl("Project.ascx");
myCnt.ID = "Control" +i;
// Panel1.Controls.Add(myCnt);
form1.Controls.Add(myCnt);

}
hiddnCnt.Value = cnt.ToString();

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top