Event not firing. User control with a repeater that contains a bu

J

Jerry C

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
 
M

Manish Bafna

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.
 
S

Steven Cheng[MSFT]

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.
 
J

Jerry C

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

--
Jerry


Steven Cheng said:
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.
 
S

Steven Cheng[MSFT]

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.
 
J

Jerry C

Steven,

Thank you for the reply.
I have to move on to other stuff. I solved the problem by redirecting to the
page whenever I needed to change the data set. So now when I save and get a
new dataset I just redirect and now I have a all new page.
 
S

Steven Cheng[MSFT]

Hi Jerry,

Thanks for your followup.

If you come back on this later and need any further help on this, please
feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top