سؤال

I have a custom DataFormWebPart that renders some content based on an XSLT. Inside the XSLT I have a button that does a postback like so:

<input type="button" value="..." name="..." 
       onclick="javascript: {ddwrt:GenFireServerEvent('__name')}" />

I don't really know how to treat this event at the server side and the docs I could find are not very useful.

How do I treat this on the server side - in the WebPart or (preferably) in the Page that contains my WebPart?

هل كانت مفيدة؟

المحلول 2

I've eventually added my code in the DataFormWebPart.PreprocessPostBackEvent method using custom action names that I then replace on method exit with __refresh.

It works for the particular case I'm having; might not work for everybody (in which case Alex Boev's answer might be useful).

نصائح أخرى

It's interesting question. If you examine the code of RaisePostBackEvent method of DataFormWebPart class you will see the processing of such actionas as _connect, _update, _insert, _commit, _cancel, _refresh, _delete, _redirect and some others. For example on __redirect command DataFormWebPart executes the following code:

else if (this.DoesPostbackEqualEvent(str2, "__redirect", true, out modifiedCommandStr))
            this.PerformRedirect(modifiedCommandStr);

And the PerformRedirect function is defined as:

private void PerformRedirect(string commandSubString)
    {
      if (this.DesignMode)
        return;
      SPUtility.Redirect(new Uri(HttpContext.Current.Request.Url, this.UnEscapeDelims(commandSubString)).AbsoluteUri, SPRedirectFlags.Trusted | SPRedirectFlags.DoNotEncodeUrl, this.Context);
    }

It looks like you cannot define and process such "events" - it's only to instruct the DataFormWebPart what to do on postback. And finally it looks like you can parametrize used command.

As for workarounds on porocessing such events - I suppose these events can be handled on server side in traditional way for postbacks:

private void HandlePostback() {
  if (this.Page.Request["__EVENTTARGET"] == "__myCommand") {
    // do your processing
  }
}

You can place such handler in custom webpart without UI and place it on the same page, for example.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top