Willem Odendaal

the coder's point of view

<August 2008>
SuMoTuWeThFrSa
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456


Navigation

I Read

Subscriptions

Post Categories



RaisePostBackEvent Oddities

I enjoy writing web controls. However, the last couple of days I've been having a lot of trouble with RaisePostBackEvent. Sometimes, no matter how hard I try, I just can't get RaisePostBackEvent to fire unless I call Page.RegisterRequiresRaiseEvent(this) in LoadPostData.

Other times my eventArgument parameter in RaisePostBackEvent is null. Even if it has been specified and looks perfect in HTML. I've then had to resort to funny code (that checks __EVENTTARGET and __EVENTARGUMENT) to get around it.

When I have to hack to get something working I'm almost 100% sure that I'm doing something wrong somewhere. But with this I am really stumped. Maybe my computer needs a new install.

Update: Problem solved! Page.RegisterRequiresRaiseEvent(this) in LoadPostData was a very wrong way to solve the problem.

The reason RaisePostBackEvent was not being called was simple - the framework will only call RaisePostBackEvent on one control. In my case the wrong control's RaisePostBackEvent was being called. In another custom control I declared a hidden <input> tag with name set to the UniqueID. This is usually the way I go about creating a control that implements IPostBackDataHandler. The framework was getting confused and called RaisePostBackEvent in the wrong control (even though __EVENTTARGET pointed to the correct control).

In this case, the other control did not implement IPostBackDataHandler and shouldn't have included the hidden <input>.

Hope this post helps some poor soul having the same problems.

posted on Wednesday, February 23, 2005 5:11 AM by willemo





Powered by Dot Net Junkies, by Telligent Systems