3

We have created a custom list with a cutom edit form using Visual Studio 2013.

At the bottom of the page, we need to add a button which will perform custom tasks and submit the form for update. I'm currently unsing a "SharePoint:RenderingTemplate" control

For example, on the "click" event of our custom button, we need to assign values based of values entered by the user.

So what I need to do on the client is something like this:

  • Call the PreSaveItem method;
  • Call our custom method;
  • Do a PostBack of the FORM.

As I read, the PreSaveItem method will be a good place to do my stuff, but I cannot discriminate the caller (eg. the SAVE button or my "Custom button")... the event data is not passed to the function;

One way to achieve my goal would be to create a server-side Custom Button with C# code.

But If I were to add a new button using XSLT (in a WebPartPages:DataFormWebPart control) I could do something like this:

<input type="button" id="mySubmit" value="My submit" onclick="javascript: if (!PreSaveItem()) return false; foo(); { ddwrt:GenFireServerEvent('__commit') }"/>

Is it possible to dynamically generate the "onclick" part within my RenderingTemplate?

Thx

  • What happens when someone modifies an item with the gridview,and doesn't click the save button? I think it would be better to build this as an event handler, not a modification of the save button. – Mike2500 May 5 '14 at 14:59
7

I am not sure i can understand correctly your question, but it seems to me that you want to submit a form via "original" save button. But would like to do your own code in between. If that's correct, what I usually do is to return 'false' in PreSaveItem. Then do all the things I need to do and then submit form with javascript like this:

function triggerPostback() {
    var saveButtonName = $('input[value$="Save"]').attr('name');
    WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(saveButtonName, "", true, "", "", false, true));
} 

Basically i grab an existing save button, then construct form submit code and submit via WebForm_DoPostBackWithOptions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.