My webpart is for SP16. I use code from this sample and when i click button in webpart, page is refreshed.

This is code for Create Item:

 private createItem(): void {
this.updateStatus('Creating item...');
  'Title': `Item ${new Date()}`
}).then((result: ItemAddResult): void => {
  const item: IListItem = result.data as IListItem;
  this.updateStatus(`Item '${item.Title}' (ID: ${item.Id}) successfully created`);
}, (error: any): void => {
  this.updateStatus('Error while creating the item: ' + error);



<button class="${styles.button} create-Button">
    <span class="${styles.label}">Create item</span>

Declare Event:

const webPart: SpFxOnPrenPnPjsWebPart = this;
this.domElement.querySelector('button.create-Button').addEventListener('click', () => { webPart.createItem(); });

I would like the page not to be reloaded when clicking a button? How do It?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.