Click here to Skip to main content
15,920,603 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: ASP.NET Calendar Web Control Pin
www.Developerof.NET13-Feb-07 18:35
www.Developerof.NET13-Feb-07 18:35 
Questionexception handling in class libraries Pin
Taurian11013-Feb-07 9:25
Taurian11013-Feb-07 9:25 
AnswerRe: exception handling in class libraries Pin
Neeraj Arora13-Feb-07 19:32
Neeraj Arora13-Feb-07 19:32 
QuestionGridDataView/SqlDataSource--Code Behind Pin
Amit Kumar G13-Feb-07 9:00
Amit Kumar G13-Feb-07 9:00 
AnswerRe: GridDataView/SqlDataSource--Code Behind Pin
Michael O.13-Feb-07 10:35
Michael O.13-Feb-07 10:35 
QuestionNo icons on Crystal Viewer Pin
DBNashville13-Feb-07 8:13
DBNashville13-Feb-07 8:13 
AnswerRe: No icons on Crystal Viewer Pin
Sylvester george13-Feb-07 20:44
Sylvester george13-Feb-07 20:44 
QuestionASP.NET RaisePostbackEvent Issues Pin
T_rexDino13-Feb-07 7:37
T_rexDino13-Feb-07 7:37 
I ran into some problems on a particular page in an application. Only on that page, for the same control that worked in other pages, the RaisePostbackEvent was not being called, even if the “__EVENTTARGET” value from the post collection was the same as the UniqueID of my control.
After a while i discovered that the event was raised but for another control in the page.

I read the msdn documentation on the event but it was kind of blurry about was really going on with the RaisePostbackEvent.
My general idea was:
-a control implements IPostBackEventHandler
-it makes sure there is a key in the posted date equal to it's UniqueID (msdn documentation)
-the postback is performed with the “__EVENTTARGET” = UniqueID
( Page.ClientScript.GetPostBackEventReference(Me, ""))

So, i thought, that in the case the conditions described above were met the control would have it's RaisePostbackEvent called. This doesn't seem to be the case in my case. So i have tried to find the problem.

I got confused reading some articles that suggested that: “Your control needs the call to RegisterRequiresRaiseEvent when it implements both IPostBackDataHandler and IpostBackEventHandler. Otherwise, the page will not invoke the RaisePostBackEvent method of your control in the Raise Postback Event phase” - Developing ASP.NEt Server Controls and Components (MSDN press) http://www.thescripts.com/forum/thread306546.html.

This still didn't seam right, from my experiences this worked (in ASP.NET 1.1 and 2.0) you could implement both interfaces and the RaisePostbackEvent will still be called. In the book the example was for button control (a sumbit button) and i belive that was a different case (“__EVENTTARGET” empty at postback) due to the fact that the postback was generated by a simple submit.

Also : “implementing IPostBackDataHandler goes over IPostBackEventhandler when control's implementation is checked (postback data checked and determined what interface implementation to call) so when control implements both interfaces, IPostBackEventHandler implementation must be manually called since framework deals then only with IPostBackDataHandler “ http://www.cetix.de/DotNetNews/Thread8197-About_the_PageRegisterRequiresRaiseEvent_and_PageRequiresPostBa.aspx . This did not sound quite right either but it got me thinking about some possible connections between the two interfaces.

Still i didn't understand the behavior in my case. I found this rather cryptic phrase in a MSDN article:

“How does ASP.NET recognize the control responsible for handling the postback? When no controls referenced in the request body implement the IPostBackEventHandler interface, the page class looks for the __EVENTTARGET hidden field, if any. The contents of the field is assumed to be the ID of the control that caused the postback. If this control implements the IPostBackEventHandler interface, the RaisePostbackEvent method is invoked.“
http://msdn.microsoft.com/msdnmag/issues/06/12/CuttingEdge/

At first i thought it was a mistake because it didn't sound like anything else i read before about the RaisePostbackEvent. So what it actually says as i understand:
-if no controls, that have their UniqueID in the post collection, implement the IPostBackEventHandler interface
- ASP.NET “looks for the __EVENTTARGET hidden field, if any” (it might be empty in the case of a simple sumbit, not through __dopostback), if the control with this UniqueID implements the IPostBackEventHandler interface, the RaisePostbackEvent method is invoked

-if there are controls that have their UniqueID in the post collection and implement the IpostBackEventHandler ???????????? THIS IS NOT ANSWERED BY THE ABOVE PHRASE.

Upon further inspection this seemed to be my case: “there are controls that have their UniqueID in the post collection and implement the IpostBackEventHandler“ (besides the control that i was expecting the RaisePostbackEvent to be called for).

Another important fact is that “the framework will only call RaisePostBackEvent on one control.” as is expected, only one control can be responsible for the postback.
But it seems that, in my case, ASP.NET considered that it was not the control with the UniqueID contained in the “__EVENTTARGET” but it was another control that implemented IpostBackEventHandler and had it's UniqueID in the post collection.

So in my case i had two solutions:
-remove the other controls UniqueID's from the post collection (the controls were rendering hidden fields with the same name as their UniqueID, so i changed the name). The controls were only implementing the IpostBackEventHandler interface.

-for the other controls that had their UniqueID's in the post collection also implement the IPostbackDataHandler interface. This seemed to help the ASP.NET know that the UniqueID's in the post collection were in order to call the methods of the IpostbackDataHandler and it din not register the other controls for a RaisePostBackEvent (if the “__EVENTTARGET” was not = to the UniqueID of the control). So it seemed, after all, to be a subtle connection between the two interfaces. It seemed that the IpostbackDataHandler had priority in some way.

So i have tried to fully understand the mechanism in which ASP.NET decides to call the RaisePostbackEvent for a control:

-if no controls, that have their UniqueID in the post collection, implement the IPostBackEventHandler interface
-ASP.NET “looks for the __EVENTTARGET hidden field, if any” (it might be empty in the case of a simple sumbit, not through __dopostback), if the control with this UniqueID implements the IPostBackEventHandler interface, the RaisePostbackEvent method is invoked for it.

-if there are controls that have their UniqueID in the post collection and implement the IpostBackEventHandler
-if the controls also implement the IpostbackDataHandler (the UniqueID is considered to be in the post collection in order for the IpostbackDataHandler methods to be called)
ASP.NET “looks for the __EVENTTARGET hidden field, if any” (it might be empty in the case of a simple sumbit, not through __dopostback), if the control with this UniqueID implements the IPostBackEventHandler interface, the RaisePostbackEvent method is invoked for it.
-if the controls don't implement the IpostbackDataHandler
ASP.NET considers that the UniqueID's are there in order for the IpostBackEventHandler methods to be called, and it goes on registering the controls for a RaisePostbackEvent, so multiple controls are registered for a RaisePostbackEvent. But because RaisePostbackEvent is called only for a single control per request, the RaisePostbackEvent is called for a control that isn't necessarily the control that has the UniqueID equalt to the value in the “__EVENTTARGET”. ASP.NET seems to call the RaisePostbackEvent for the last registered control.

This mechanism seems to explain the behavior in my case. If some of you could confirm or infirm this scenario i would appreciate it.
QuestionFormat function Pin
vidhu raj13-Feb-07 4:48
vidhu raj13-Feb-07 4:48 
AnswerRe: Format function Pin
Christian Graus13-Feb-07 8:45
protectorChristian Graus13-Feb-07 8:45 
Questionhttps for secure pages in asp.net Pin
red60mans13-Feb-07 4:28
red60mans13-Feb-07 4:28 
AnswerRe: https for secure pages in asp.net Pin
sathesh pandian19-Feb-07 23:00
sathesh pandian19-Feb-07 23:00 
QuestionConnecting to an external database from an asp.net application Pin
abiodunode13-Feb-07 3:34
abiodunode13-Feb-07 3:34 
QuestionGridView Template Field Pin
Murthy Puvvada13-Feb-07 3:19
Murthy Puvvada13-Feb-07 3:19 
AnswerRe: GridView Template Field Pin
Kschuler13-Feb-07 5:41
Kschuler13-Feb-07 5:41 
Questionclarification needed for asp.net authentication Pin
Member 309559313-Feb-07 3:17
Member 309559313-Feb-07 3:17 
QuestionHow to set dinamicly text into head Pin
papa8013-Feb-07 2:52
papa8013-Feb-07 2:52 
AnswerRe: How to set dinamicly text into head Pin
gauthee13-Feb-07 3:24
gauthee13-Feb-07 3:24 
AnswerRe: How to set dinamicly text into head Pin
sstocker13-Feb-07 4:57
sstocker13-Feb-07 4:57 
Questionalert in ajax toolkit 2.0 Pin
kuwl_mark13-Feb-07 2:37
kuwl_mark13-Feb-07 2:37 
Questionmultilingual site Pin
saqib8213-Feb-07 2:32
saqib8213-Feb-07 2:32 
AnswerRe: multilingual site Pin
Tad McClellan13-Feb-07 11:06
professionalTad McClellan13-Feb-07 11:06 
AnswerRe: multilingual site Pin
sathesh pandian19-Feb-07 23:10
sathesh pandian19-Feb-07 23:10 
Questionproblem in fetching and showing images from Share point site to end user site grid Pin
ankushmn13-Feb-07 2:28
ankushmn13-Feb-07 2:28 
QuestionSubmitting to another form Pin
Tyrone_whitey13-Feb-07 2:05
Tyrone_whitey13-Feb-07 2:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.