1

I've spent the better part of three days trying to wrap my head around UpdatePanel and _DoPostBack to find a solution to my problem with my infopath browser enabled form.

I have a simple script that displays a popup on a button click which works until a postback occurs (that's what I'm assuming anyway). I have a choice control (combobox) that when populated performs a postback. After the postback occurs I lose the button functionality described above until I refresh (F5). I'm looking for a solution client side that I can implement in a js file as I use CEWP's to implement my code. I'm not against making changes to the page itself using SPDesigner and advanced editing, however, I would like to keep it in the js file as much as possible.

If I can get past this problem it will open up way more options for me as I'm currently only running scripts on pages with no postbacks until the form is saved and exited.

I've tried dissecting this tutorial, however, I'm unsure how to implement:
http://encosia.com/easily-refresh-an-updatepanel-using-javascript/

I've tried numerous solutions to no avail such as:
jQuery autocomplete dissapears on postback and the JQuery .Live() / .On() solution.

See my simple script below:

 <script language="javascript" type="text/javascript">
 ExecuteOrDelayUntilScriptLoaded(pageLoad, "sp.js");
   function pageLoad(sender, args)   
    {       
    // Button click - Set Due Date  
 $("#ctl00_m_g_a8d36925_babc_41fa_86da_95fa02c75109_FormControl0_V1_I1_B2").click(function() 
        {
           alert("It worked...");
        }); // End Due Date
    } // End pageLoad  
</script>
  • Can you provide the script? And have you ran IE Dev tools during this process? If there's any javascript errors, it should tell you. – wjervis Jul 7 '15 at 18:11
  • I get no errors and console shows nothing as well. It just doesn't work after I select a choice in the drop down field. I've added my script to the original post... – Ghoztrider Jul 7 '15 at 19:36
1

Selecting a value in your dropdown is probably causing a postback, which can mess up your JavaScript and may mess with control IDs etc. Monitoring closely in your browser's developer tools should give a better idea of what's going on.

Unless you're doing something more complicated than your example above, I would suggest that it would be far easier to achieve what you want with InfoPath's built in functionality.

For example, rather than using JS to set the title for a control, you can add a textfield to your form, set it to be read-only and format it to have no shading and no borders. That will effectively give you a label you can place beside your control, and you can set it's text value using a rule on the drop down.

Instead of a popup alert, you can repeat the same trick as above to create an "alert label", but add an extra field to your form's datasource to say if it should be displayed or not. Then add a conditional formatting rule to your "alert" label, to hide depending on the value of that field. Or to get a bit fancier, you could add a section to your form, put the "alert label" in the section and set the conditional formatting rule on that. Then in the rules for your dropdown, set the text for the alert and set the field to say if it should be displayed or not.

It's not the prettiest solution from a programmer's perspective, but it should work very reliably in InfoPath.

  • I do agree with you on the alert portion of the script, again this is just a test sample script. I'm actually looking to grab information from another list based on the id (which I've done successfully when no postback is required). I didn't want to test this with the full script if I can't even get the alert popup to work. I will research more on postback. Thanks. – Ghoztrider Jul 8 '15 at 12:51
  • One thing worth checking, is that with the InfoPath controls, you can control when they trigger a postback. Right click on the control in designer and go to it's properties. On the last properties tab you can set if the control should trigger a postback "Always", "Never" or "If Required" or something like that. You could try setting your control to never and see if that helps. – Steven Mulkerrins Jul 14 '15 at 14:40
  • Very close Steven! This gets me halfway there, I can use this trick if I'm not cascading dropdowns, however, I still need the post back on some occasions. Thanks for tip! – Ghoztrider Jul 14 '15 at 19:40

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.