Monday, June 09, 2008

Roll Your Own Postback Event

I found out how to cause javascript to trigger a server side event by trying to make something happen with the Telerik control suite ( This might be of interest to some of you, and I believe if your updated control is wrapped in an ajax update panel a full post back may not even take place (at least with Telerik's controls the below technique seemed to work as an ajax enabled partial post back.

Experiment for yourself.


<script type="text/javascript">
function myfunction(param)
"<%= myControl.ClientID %>", "myargs");

And in your in your page code...

   protected override void RaisePostBackEvent ( IPostBackEventHandler source, string eventArgument )
base.RaisePostBackEvent ( source, eventArgument );
if ( source == this.myControl && eventArgument.IndexOf ( "myargs" ) != -1 )
// Do whatever here

No comments: