Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,


I have a usercontrol which is dynamically loaded into the page.... I ve a button inside the user control..On click of it button (save_click) click event not firing....Page load event is getting fired in tat page but not tat button !!! Any suggestions frens ??
Posted
Comments
Unareshraju 6-Aug-12 7:56am    
s i also faced this issus in silvetlight 4.o but not resolved yet now.

Anything that's dynamically added after the viewstate is restored, does not exist for viewstate, and therefore has no events. You need to add it sooner. Read up on viewstate management and dynamic controls.
 
Share this answer
 
Comments
darshan559 6-Aug-12 6:40am    
Thnxs Christian for ur suggestion...can u be more specific abt wht shud i do for firing the button click event..thanks in advance...
_Amy 6-Aug-12 7:48am    
Correct. +5!
Christian Graus 6-Aug-12 16:19pm    
Specifically, you should do what I specifically said. It involves reading and learning.
darshan559 7-Aug-12 3:15am    
@christian graus -It has nothing to do with ViewState. ViewState is responsible for maintaining the state of the controls in the control tree -- not the state of the control tree itself! . Dynamically created controls will not exist on the next postback unless you add them to the control tree once again....so dis issue need to be solved by loading control on every load..!!!
Christian Graus 7-Aug-12 3:39am    
Correct. That is exactly my point. Later versions differentiate between control state and viewstate, but they are both part of the same thing, and both rely on the control always being created BEFORE viewstate is created. If you load it too late, it still will have no events, as it won't be part of the control tree when events are constructed
Call ur Button Click Event In your PageLoad


protected void Page_Load(object sender, EventArgs e)

{
Button.Click += new EventHandler(Button_Click);

}

void Button_Click(object sender, EventArgs e)
{

ButtonClick Code.....
}
 
Share this answer
 
when you are adding button on form run-time, Have you added Event-handler for click event of that button?

Happy coding!
:)
 
Share this answer
 
Comments
darshan559 6-Aug-12 6:38am    
Thnxs aarthi for ur reply..ya i ve added it ...!!
Aarti Meswania 6-Aug-12 6:53am    
refer this link "http://stackoverflow.com/questions/1775788/asp-net-dynamic-command-button-event-not-firing"
read some of last reviews on that page. may it be useful to solve this problem.

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