Basic Question

M

Mark Fox

Hello,

I am not sure if this is possible, but it's a simple
enough situation that it seems as though it would be.

I have a page main.aspx with a couple user controls
in it Control1.ascx and Control2.ascx. I am attempting
to figure out how to hook up an event handler of some
sort in the user controls so that when the page is
submitted, I could handle it. When I developed a custom
server control I did this through implementing
IPostBackEventHandler and IPostBackDataHandler, but I
don't know how to do this in a user control. I tried
implementing the two interfaces in a user cotnrol, but
they didn't work. Thanks for your help!
 
T

Teemu Keiski

Well, generally thinking you could expose a public event on the Page that
the user controls then specify handlers for it (that is called when Page
raises the event). But what kind of event it is about? What you have tried
for now? Please provide bit more details.

--
Teemu Keiski
MCP, Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com
 
Y

Yan-Hong Huang[MSFT]

Hello Mark,

Could you please look into http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconimplementsdirective.asp?
frame=true?

It lists code samples demonstrating a user control that includes an @ Implements directive to access the properties and
methods of the IPostBackEventHandler interface.

Hope that helps.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!Content-Class: urn:content-classes:message
!From: "Mark Fox" <[email protected]>
!Sender: "Mark Fox" <[email protected]>
!References: <[email protected]> <[email protected]>
!Subject: Re: Basic Question
!Date: Thu, 31 Jul 2003 07:11:41 -0700
!Lines: 72
!Message-ID: <[email protected]>
!MIME-Version: 1.0
!Content-Type: text/plain;
! charset="iso-8859-1"
!Content-Transfer-Encoding: 7bit
!X-Newsreader: Microsoft CDO for Windows 2000
!Thread-Index: AcNXbaoWPPE6LSAAT1yMujEHUeLTyA==
!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
!Path: cpmsftngxa06.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet.buildingcontrols:6873
!NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
!
!Teemu,
!
! I have tried to derive the user controls from
!IPostBackEventHandler and IPostBackDataHandler and
!implement the interfaces, but the implementations are
!never called so it seems that those interfaces won't
!wonrk on user controls. Basically, I have a web form
!AddNewUser.aspx and a couple of user controls that handle
!sending e-mail notifications/reminders
!(EmailReminder.ascx and EmailNotification.ascx) and a
!date/time picker user control (DateTimePicker.ascx).
!When the user clicks the "Add" button to add the new
!user, the EmailReminder.ascx and EmailNotification.ascx
!have to run code to send and schedule the e-mails. I put
!the code in a user control because I am looking to reuse
!it on a bunch of pages (AddNewUser.aspx is just the first)
!and the UI doesn't lend itself to being a server
!control. I could give the user controls public methods
!OnSubmit() and have the Page's OnSubmit event handler
!explicitly call [UserControl].OnSubmit(). This might be
!easier than setting up an event in the Page and event
!handlers in the user control, but it would better for the
!user controls to somehow register their own postback
!handlers so the Page that contains them doesn't have to
!do anything. If this still doesn't make sense or you
!would like more information please let me know. Thanks
!for your help!
!
!>-----Original Message-----
!>Well, generally thinking you could expose a public event
!on the Page that
!>the user controls then specify handlers for it (that is
!called when Page
!>raises the event). But what kind of event it is about?
!What you have tried
!>for now? Please provide bit more details.
!>
!>--
!>Teemu Keiski
!>MCP, Designer/Developer
!>Mansoft tietotekniikka Oy
!>http://www.mansoft.fi
!>
!>AspInsiders Member, www.aspinsiders.com
!>ASP.NET Forums Moderator, www.asp.net
!>AspAlliance Columnist, www.aspalliance.com
!>
!>
!>!>> Hello,
!>>
!>> I am not sure if this is possible, but it's a
!simple
!>> enough situation that it seems as though it would be.
!>>
!>> I have a page main.aspx with a couple user
!controls
!>> in it Control1.ascx and Control2.ascx. I am attempting
!>> to figure out how to hook up an event handler of some
!>> sort in the user controls so that when the page is
!>> submitted, I could handle it. When I developed a
!custom
!>> server control I did this through implementing
!>> IPostBackEventHandler and IPostBackDataHandler, but I
!>> don't know how to do this in a user control. I tried
!>> implementing the two interfaces in a user cotnrol, but
!>> they didn't work. Thanks for your help!
!>
!>
!>.
!>
!
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top