Get Client Side value to an Event

by Erik Lane 14. November 2004 13:41

Ok. Now I've got the table state thing figured out now is my first real stab at using a required client-side script (Plumtree) and have it post back the page so I can catch the event and return values to process the data as needed. This could all be done via client-side script but I've already written 90% of the needed code in the codebehind and I want to reuse it.

So how do I trigger the event-handler and pass it a parameter value from the client-side script? I looked and looked and I saw many different styles on how to raise an event but most of what I read was dealing with custom server controls. So what I ended up doing was registering a hidden field (initially blank) on Page_Load that would then be populated by the client-side script when it ran. So on postback I would check the hidden field for a value. If there was a value then I knew the client-side script caused the postback and then I would call the needed event and pass in the value from the hidden field.

How elegant is this? I don't know but it works. I really was wanting a way to keep everything in the code-behind and only use client-side script and hidden fields as a last resort...that's were I was at. See the code snippets below and if you've got a better way please comment.


    51: // Hidden field to store return value from pt:tree
    52:       RegisterHiddenField("__ObjectID", "");
    53:  
    54:       if(Page.IsPostBack)
    55:       {
    56:         _links = (PortletHyperlinks)ViewState["LinkCollection"];
    57:         // Check for return from pt:tree
    58:         if(Request.Form["__ObjectID"].Length != 0)
    59:           DrawTable("addDoc");
    60:       }
    61:       else
    62:       {

Tags:
Comments are closed