|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Event not firing. User control with a repeater that contains a buThis control itself is added dynamically in a multiview view in another user control kind of like this. page usercontrol multiview view usercontrol repeater item button item button end repeater end usercontrol end view end multiview end usercontrol end page this works most of the time. When I do a data save and replace the data in the control the button in the repeater does not work. but when I press the button the second time it works. From some posts on the web it seems the event handler is missing or the event misses it or something like that. I was hoping someone would have had some similar situations that could help Thank you -- Jerry Hi,
Most probably you would be using code something like this: <asp:Repeater id="Repeater1" OnItemCommand="Button_ItemCommand" runat="server"> Note that in the Page_Load event, you need to ensure that subsequent postbacks do not result in another databinding process. If you do not test for postbacks using the IsPostBack property, the Button_ItemCommand event will not be serviced. -- Show quoteIf my answer helped you,then please do press Yes below. Thanks and Regards. Manish Bafna. MCP and MCTS. "Jerry C" wrote: > I have a user control with a repeater that has buttons in the items. > > This control itself is added dynamically in a multiview view in another > user control > > kind of like this. > > page > usercontrol > multiview > view > usercontrol > repeater > item > button > item > button > end repeater > end usercontrol > end view > end multiview > end usercontrol > end page > > this works most of the time. When I do a data save and replace the data in > the control the button in the repeater does not work. but when I press the > button the second time it works. From some posts on the web it seems the > event handler is missing or the event misses it or something like that. I was > hoping someone would have had some similar situations that could help > > Thank you > > > -- > Jerry Hi Jerry,
Based on your description, you have two usercontrols, one is statically put on a page, and another is dynamically loaded into a MultiView in the first upper level usercontrol. I think the problem you met here is likely due to dynamically added webcontrol. I've met many similar issue about control displaying or postback event handling when being added dynamically. Would you provide some code logic on how to create the inner user control and add it into MultiView? I have performed some test on my side and it seems normally the dynamicaly added usercontrol(with repeater in it) can correctly handle postback event. Here is my main usercontrol's code which programmatically add nested usercontrol into multiview: =====main usercontrol========= public partial class uc_MainUC : System.Web.UI.UserControl { protected void Page_Init(object sender, EventArgs e) { Control uc = Page.LoadControl("~/uc/RepeaterUC.ascx"); this.MultiView1.Views[0].Controls.Add(uc); } ================ If you need, I can send you the complete test page and usercontrol code for your reference. Sincerely, Steven Cheng Microsoft MSDN Online Support Lead ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Steven and Manish,
Thank you for the replys. The problem seems to be with the postback and rebinding the repeater. When I rebind on postback with the data used to build the page the first time all the buttons work OK. But when I save data changes I get a new set of data from the SQL server and bind it to the repeater, this is when the buttons lose their event wireup. The question now is how do I replace the data in the repeater and databind without losing the button event wireup. Thank you -- Show quoteJerry "Steven Cheng[MSFT]" wrote: > Hi Jerry, > > Based on your description, you have two usercontrols, one is statically put > on a page, and another is dynamically loaded into a MultiView in the first > upper level usercontrol. I think the problem you met here is likely due to > dynamically added webcontrol. I've met many similar issue about control > displaying or postback event handling when being added dynamically. > > Would you provide some code logic on how to create the inner user control > and add it into MultiView? I have performed some test on my side and it > seems normally the dynamicaly added usercontrol(with repeater in it) can > correctly handle postback event. Here is my main usercontrol's code which > programmatically add nested usercontrol into multiview: > > =====main usercontrol========= > public partial class uc_MainUC : System.Web.UI.UserControl > { > protected void Page_Init(object sender, EventArgs e) > { > > Control uc = Page.LoadControl("~/uc/RepeaterUC.ascx"); > > this.MultiView1.Views[0].Controls.Add(uc); > > } > > ================ > > If you need, I can send you the complete test page and usercontrol code for > your reference. > > Sincerely, > > Steven Cheng > > Microsoft MSDN Online Support Lead > > > > ================================================== > > Get notification to my posts through email? Please refer to > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif > ications. > > > > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues > where an initial response from the community or a Microsoft Support > Engineer within 1 business day is acceptable. Please note that each follow > up response may take approximately 2 business days as the support > professional working with you may need further investigation to reach the > most efficient resolution. The offering is not appropriate for situations > that require urgent, real-time or phone-based interactions or complex > project analysis and dump analysis issues. Issues of this nature are best > handled working with a dedicated Microsoft Support Engineer by contacting > Microsoft Customer Support Services (CSS) at > http://msdn.microsoft.com/subscriptions/support/default.aspx. > > ================================================== > > > > This posting is provided "AS IS" with no warranties, and confers no rights. > > > > > > > > Thanks for your reply Jerry,
I think your new description provided the key point here, "rebind the data" is surely likely to cause such problem. In my previous test case, I just simply put a datasource control in the usercontrol to populate data in repeater. So as you mentioned that you'll rebind the repeater with new dataset when you put save button, then where did you do the rebind operation(in Load or ...)? I think it will cause problem if you rebind the repeater before the postback event(of the save button's click) be processed because rebind the repeater will change the control structure so as to make the postback event unable to trigger the original control. If possible, would you provide some further code logic on how to rebind the repeater(in which event). You can also first try moving the rebind code to a later event(such as after you've doing the task in postback event) to see whether it helps. Sincerely, Steven Cheng Microsoft MSDN Online Support Lead This posting is provided "AS IS" with no warranties, and confers no rights. |
|||||||||||||||||||||||