[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to get RaisePostBackHandler to fire before CreateChildControls is called in a Custom Composite Control?

Posted on 2009-04-07
5
Medium Priority
?
520 Views
Last Modified: 2013-12-17
Hi,

I am looking at two examples in the msdn docs.

The  first example I am looking is here : http://msdn.microsoft.com/en-us/library/aa719907(VS.71).aspx it states that by adding the event to the events property of the control it is more efficient. Also in the example they are implementing IPostBackEventHandler.

In this second example found here, http://msdn.microsoft.com/en-us/library/3257x3ea.aspx

They are are kind of doing basically the same thing but no implementation of IPostBackEventHandler.

I have a compsite control that may have up to 3 Image buttons at the same time so I am not sure if I need to create 3  private static readonly object EventSubmitKey =    new object(); or just one?

I am also not sure if the IPostBackEventHandler should be implemented or not as the second example doesn't implement it, so I am assuming the CompsiteControl already does?

In this second example the buttons click event is handled in the composite control then the submit event is raised. Is it possible to handle a buttons click event in the composite control first than bubble it back to the Page or is that what this is doing?

Thanks!

I originally posted this question here:  http://forums.asp.net/t/1405321.aspx
I have since discovered that ImageButtons implement the IPostBackEventHandler interface themselves thus causing the issue of the RaisePostBackEvent not firing. I then decided to just add an image to my composite control and was able to get the RaisePostBackEvent to fire but not until after the CreateChildControls method already fired.
Below is a code snipped of what I tried that was able to get the RaisePostBackEvent to fire but like I stated this did not fire untill after the CreateChildControls method executed. I am starting to think that is how it is suppose to work but I am not sure.
The reason I wanted the event to fire before the CreateChildControls method is so I can dynamically change what controls are in my Composite Control.
Literal myLiteral = new Literal();
myLiteral.Text = "<img src=\"Images/next.gif\" onclick=\"" +
Page.ClientScript.GetPostBackEventReference(this, "") + "\" />";
currentPanel.Controls.Add(myLiteral);

Open in new window

0
Comment
Question by:OutOfTouch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Accepted Solution

by:
OutOfTouch earned 0 total points
ID: 24135560
Upon further reading I don't believe it is possible to have the RaisePostBack method fire before the CreateChildControls Method. That is just not how the events are processed.
I guess I should have not listened to another's advice in the MS forum where I originally posted this question well at least not completely, instead  I should have paid closer attention to what the MSDN Doc says.
From the msdn docs on CreateChildControls method:
Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
The following only works if I don't use an ImageButton because the image button already implements the IPostBackEventHandler interface, the UniqueID(EVENTTARGET) of the image button causing the postback would not be the same as my composite control that houses this ImageButton, this would mean the RaisePostBack event in my composite control would never fire.
So instead of an image button I just used an html image and I did discover that if I let my control run the CreateChildControls method on postback than it runs the RaisePostBackMethod, I can than set ChildControlsCreated  to false which will cause the CreateChildControls method to fire again, this causes another issue,  my control is now empty when it renders after the additional call to CreateChildControls, I think this is related to viewstate but I am not sure.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question