Click here to Skip to main content
15,879,864 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi ,

I have created one user control. Ascx file named "Movable_Text".

On Add_contol_button click i have to add user control on my master page.

For this my button click coding is
public static int li_Count = 0;
   protected void Add_contol_button_Click(object sender, EventArgs e)
           Movable_Text mt = new Movable_Text();
           mt.ID = Convert.ToString(li_Count);
           mt = LoadControl("Movable_Text.ascx") as Movable_Text;
           mt.EnableViewState = false;
       catch { }

CPH_Master is master page's content place holders
In this case only one control is added on my form. When i clicked twice on Add_contol_button again only one user control appears.

My need is each time clicking on Add_contol_button new user control is created on form. Ex. If i clicked 5 times then 5 User control appears on form.

Please please suggest me proper way for achieving this
Updated 16-Jun-11 22:33pm

Your controls don't exist. You need to add them all every time you postback, or they disappear. Also, they will not have viewstate, so you won't be able to get values from them. They need to be created before page_load for viewstate to work.
Share this answer
Share this answer
Alizee@CP 17-Jun-11 6:20am    
Hello walter ,

I tried but the control created earlier disappears immediately.

Eery time a single control is created here.

Please guide me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900