problem whil adding user control dynamically multiple times

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default problem whil adding user control dynamically multiple times

    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.VarCh ar,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 = "ritesh_solanki@yahoo.com";
    //Session["ERResumeID"].ToString();

    SqlHelper.ExecuteNonQuery(CommonClass.GetConnectio nString(),CommandType.StoredProcedure,"spInsertEmp loyeeExperience",ParamCompany,ParamLocation,ParamP eriod,ParamProject,ParamDesc,ParamTech,ParamResume ID);

    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();

    }

    parulrgupta@gmail.com Guest

  2. Similar Questions and Discussions

    1. Using the same User Control multiple times on one page
      How can I reuse a User Control multiple times on a single page? I have one created that pulls and hyperlinks the most recent news items from the...
    2. Dynamically Adding User Control with Child User Control
      I have a user control that has a child user control. If I drag this onto the page, it appears and functions normally. If I attempt to add the...
    3. Dynamically adding a user control to aspx page
      I am using an aspx page called USProfile.aspx. It has a placeholder control. A user control called USData is added to placeholder control...
    4. Adding dynamically user control (ASCX) into asp.net page and handling OnClick event
      Hi, I've been reading a lot's of Q&A on user controls but none seem to answer my question. Here it is. I need to add dynamically a user control,...
    5. Page Load fired 3 times Web user control is embedded in a custom control
      Hi, I have built a custom control that build a table with 3 cells in it. The custom control is designed to add all child controls to cell#2,...
  3. #2

    Default Re: problem whil adding user control dynamically multiple times

    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
    <parulrgupta@gmail.com> ha scritto nel messaggio
    news:1145337236.319946.6170@i39g2000cwa.googlegrou ps.com...
    >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.VarCh ar,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 = "ritesh_solanki@yahoo.com";
    > //Session["ERResumeID"].ToString();
    >
    > SqlHelper.ExecuteNonQuery(CommonClass.GetConnectio nString(),CommandType.StoredProcedure,"spInsertEmp loyeeExperience",ParamCompany,ParamLocation,ParamP eriod,ParamProject,ParamDesc,ParamTech,ParamResume ID);
    >
    > 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();
    >
    > }
    >

    Alessandro Zifiglio Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139