Multiple instances of custom web part on same page conflicts

Andrew Campkin asked on February 7, 2017 22:34

Hi, I have created a custom web part that produces a PDF from user entered input fields on click of a button.

I am having a problem with multiple of this web part on the same page, where regardless of which web parts button is clicked, only the first part's PDF is generated, IE the code behind runs for the first instance of the web part regardless of the trigger. When debugging, the properties are that of the first part rather than the part clicked.

This is complicated by the fact that the display of the web part acts similar to static HTML, where the content administrator user can enter some HTML to display, so the button that triggers the form submit is just some piece of user editable HTML.

I have had a lot of problems getting the PDF generation code to run on submit, because the submission is not a page control. Does anyone have any suggestions about a "right" way to do this?

Recent Answers


Zach Perry answered on February 7, 2017 22:43

Why does the content Administrator need to be able to edit the control? Are they adding fields? Or just changing the layout?

0 votesVote for this answer Mark as a Correct answer

Andrew Campkin answered on February 7, 2017 23:07

The content administrator or a developer is entering the content that displays on the web part, as the fields/content will be different for each instance.

The setup for the web part includes a rich text editor to enter this content. The problem is the way I've done it, the button to submit the "form" is inside this content.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 7, 2017 23:25

Without seeing what custom code you have written, it's hard to troubleshoot specifically. Are you getting specific errors? Have you debugged through the page which has 2 webparts on it? What errors do you get?

0 votesVote for this answer Mark as a Correct answer

Andrew Campkin answered on February 7, 2017 23:31 (last edited on February 7, 2017 23:34)

I'm not getting any errors, the problem I'm having is because the submission button is part of the custom HTML then the code behind that creates the PDF only runs for the first instance of the web part that is on the page.

I can't find a way to set up a button submit handler out of the custom HTML, so I'm fishing for ideas to do this in a completely different way.

I'll try and show what the page looks like below, I have code already that can load up the PDF form and insert field values from the request object:

==== Web part instance 1====

Textfield1

Textfield2

Download PDF button 1

==== Web part instance 2====

Textfield3

Textfield4

Textfield5

Download PDF button 2

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 8, 2017 16:15

What custom HTML code? Is this javascript you're having interact with the control(s) or is the 3rd party library for creating the PDF's needing some custom html?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.