Click here to Skip to main content
15,913,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am creating two image buttons dynamically on a page and on the click event of these buttons i am creating some more image buttons but when i am trying to fire click event on newly created buttons these buttons gone invisible and no event is fire
Posted
Updated 13-Sep-12 19:27pm
v2

Yes, because you are creating the buttons on the click event of a button. That's why the newly created buttons are unable to restore the viewstate for that.
Better you create your buttons in Page_InIt event and make them invisible to the user. On click of button you can make those created buttons visible.
Otherwise you need to restore the viewstate of the controls. In that case refer the link:
Retaining State for Dynamically Created Controls in ASP.NET applications[^]
ViewState in Dynamic Control[^]

--Amit
 
Share this answer
 
Hello,

The problem is that for the dynamic created control view state is not maintain. So you need to create viewstate for dynamic create control.
See the following link. You will get the idea how to create the dynamic controls and its viewstate.

Retaining State for Dynamically Created Controls in ASP.NET applications[^]

I hope it might be help you.

Thanks,
Viprat
 
Share this answer
 
Hi,

Make sure that you are creating the button early in the page life cycle, may be in Page_Init or Page_Load. Because, the dynamically created buttons does not hold view state. that is why you have to create the controls every time on Page_Init or Page_Load. also because the event handling will occur after the page Init stage. So, create the Image button in Page_Init event also assign onclick delegate in page_Init event only. then try.

for more refer this[^]

Hope it helps.
 
Share this answer
 

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