Calendar control not raising events in UserControl

C

Colin Young

I have a UserControl that contains a calendar control. The calendar is not
raising events (month navigation, date selections, etc.). I've checked that
the OnSelectionChanged event has a handler being registered. Is there
anything else obvious or otherwise that I've missed? Is there a problem
using it in a UserControl?

Thanks

Colin
 
J

Jacob Yang [MSFT]

Hi Colin,

Based on my research and experience, I would like to share the following
information with you.

Before the Page_Load event, asp.net loads in all the ViewState data, for
example, recreating your controls on web page. Then it matches up the
control that raises the postback with the actual control which was
regenerated from the ViewState. At this point, ASP.NET knows that this
particular control was fired and it adds the handler event to the list of
events that must be executed.

If the load phase was after the restore of the ViewState data, the event
will not fired as expected.

The ASP.NET page framework provides a technique called event bubbling that
allows a child control to propagate events up its containment hierarchy.
Event bubbling enables events to be raised from a more convenient location
in the controls hierarchy and allows event handlers to be attached to the
original control as well as to the control that exposes the bubbled event.

For more information, plesae check this article:

Bubbling an Event
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconbubblingcommandeve
nt.asp

Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
C

Colin Young

I've already checked the control tree using tracing and the UserControl that
is giving me trouble is being recreated with the same ID after postback, so
there should be no trouble matching up the event with the correct control.
The control is not dynamically created so there should be no trouble with it
being created too late in the process.

I'm attempting to handle the event within my User Control. Even if I add an
override for handling event bubbling, the OnEventBubble is never called. The
page does postback, it's just that the event never gets raised.

Just to be clear I have created a Web User Control, not a Custom Server
Control, although I may convert to a custom control since I have more
experience with those and have generally had better luck with them. I only
created a user control because I thought it would be quicker.

Colin
 
C

Colin Young

Nevermind... I've figured out what the problem is and it has nothing to do
with the user control or the calendar. My page is accessed by a
server.transfer and uses url rewriting, so the postback isn't really
occuring.

Now that I know what the problem is I just need to figure out how to fix
it...

Colin
 
J

Jacob Yang [MSFT]

Hi Colin,

I am sorry if there is any misunderstanding.

After reviewing your response, I have a little puzzle on your issue.

As I understand, you developed a UserControl, an ascx file, which contains
a Calendar server control. Then you instantiate the user control in a web
page.

In another web page, you use the Server.Transfer to invoke the web page
where the user control was located.

However, the problem is that in this situation, some events on the Calendar
inside the user control are not fired as expected.

On my side, to reproduce the issue, I did the following tests.

1. Create a web user control, a class inherits from
System.Web.UI.UserControl.
2. Drag and drop a Calendar control onto the user control.
3. Put a Response.Write statement inside the SelectionChanged handler of
the calendar control.
4. Create a web page and drag the ascx file (the user control) onto this
web page.
5. Create another webpage, which contains a button. In the click event of
the button, I just do the following thing:

Server.Transfer("the web page where the user control was located")

6. Set the web page created in step 5 as the start web page. Compile and
run the application. When the web page launches up, click the button to
trigger the Servevr.Transfer.
7. When the web page where the user control comes up, I click certain day
on the Calendar control, the SelectionChanged event is fired successfully.

If I have misunderstood your concern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
C

Colin Young

I'm also using URL rewriting. I encountered the problem detailed in KB
Q817036. The work-around presented in that article has cleared up the
problem for me.

Thanks for taking the time to investigate my issue.

Colin
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top