Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Event not firing. User control with a repeater that contains a bu

Reply
Thread Tools

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

 
 
Jerry C
Guest
Posts: n/a
 
      05-10-2007
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
 
Reply With Quote
 
 
 
 
Manish Bafna
Guest
Posts: n/a
 
      05-10-2007
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.
--
If 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

 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      05-10-2007
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/subscripti...ult.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/subscripti...t/default.aspx.

==================================================



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







 
Reply With Quote
 
Jerry C
Guest
Posts: n/a
 
      05-11-2007
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[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/subscripti...ult.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/subscripti...t/default.aspx.
>
> ==================================================
>
>
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>
>
>
>
>
>

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      05-14-2007
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.



 
Reply With Quote
 
Jerry C
Guest
Posts: n/a
 
      05-15-2007
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.
--
Jerry


"Steven Cheng[MSFT]" wrote:

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

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      05-16-2007
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Repeater Contains Web User Control Webmills ASP .Net 3 10-18-2006 12:15 PM
Databinding in a user control that contains another user control StraussGuy@hotpop.com ASP .Net 0 01-07-2005 04:55 PM
Event not firing for user control inside user control vatech1993 ASP .Net 4 12-11-2004 02:51 PM
Regex problem, match if line contains <a>, unless it also contains <b> James Dyer Perl 5 02-20-2004 12:29 PM



Advertisments