none
Using Updatepanel in sharepoint 2013 web part

    Question

  • Hi Experts,

    We are facing problem related to updatepanel in sharepoint 2013. we have a sample webpart that includs a label and a button, we want to write somthing to label in click event of button without refreshing the whole page. Our sample code is as followed :

     <asp:UpdatePanel runat="server" ID="UpdatePanel1">
            <ContentTemplate>
                <asp:Label ID="lbl" runat="server" Text="Loaded" Visible="true"></asp:Label>
                <asp:Button ID="btn" runat="server" OnClick="btn_Click"/>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btn" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>

            protected void btn_Click(object sender, EventArgs e)
            {
                lbl.Text = "BUTTON CLICKED !";
                lbl.Visible = true;
            }

    We have tried the solution mentioned on this link but could not achieve our goal.

    Any solution for this problem along with sample code will be highly appreciated.

    Thanks.


    A Learner


    Wednesday, April 03, 2013 3:47 PM

All replies

  • Hi

    You don't need this:

     <Triggers>
         <asp:AsyncPostBackTrigger ControlID="btn" EventName="Click" />
     </Triggers>

    all child controls in UpdatePanel by default act as triggers so you don't need this part and it will automatically do the job.

    Saturday, April 27, 2013 11:04 AM
  • Hi,

    I also have this problem... How can I use a updatePanel inside a Visual WebPart...

    Any new findings?

    Thx

    Bernhard

    Sunday, July 14, 2013 11:45 AM
  • Hi Hunain,

    You don't need the block for "Triggers". Please find below a sample code which works perfectly.   

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
           <ContentTemplate>
               <asp:Label ID="lblTest" runat="server" Text="Label"></asp:Label>
                <asp:LinkButton ID="AddLink" runat="server" OnClick="AddLink_Click">Click Me</asp:LinkButton>
            </ContentTemplate>
        </asp:UpdatePanel>
    
    
    protected void AddLink_Click(Object sender, EventArgs e)
    {
         lblTest.Text = "I am Invoked";
    }

    Sunday, July 14, 2013 4:08 PM
  • Hi Narahari,

    thanks für your reply... Unfortenatly it deoesn't work for me in a Webpart...

    I always have a full page request in SharePoint 2013...

    Any further hints?

    Bernhard

    Sunday, July 14, 2013 4:20 PM
  • Have you added to add script manager in your page? You can try to enable script debugging in IE and try to find out what exception you are getting on client side.

    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com>

    Monday, July 15, 2013 6:02 AM
  • Hi Bernhard,

    I feel there's a bad javascript error on the page which is breaking the Microsoft's javascript for UpdatePanel. Please turn on your IE developer console and debug. Check whether you have any Page load JS errors or button click JS errors? Mostly Javascript errors break the AJAX logic and make the postback behave like a regular postback. 

                Also, try removing the update panel and make sure the page works perfectly without any Javascript errors. Then, simply add the update panel. Please note that normally the script manager or trigger blocks are not required in SP2013. Only UpdatePanel should do the trick.

    Narahari



    Monday, July 15, 2013 7:23 AM
  • Hi Sohel,

    thanks for your reply. Yes I added a scriptmanager... Just beside without Scriptmanager a error is raised. For me no error is thrown but instead of an ajax request an full page reload is done.

    I followed this "tutorial" 
    http://weblogs.mysharepoint.de/blogs/fabianm/archive/2008/06/28/ajax-funktionen-in-sharepoint-webparts-integrieren.aspx  (in German)

    But in short words:

    1) Register ScriptManager

    2) Enable UpdatePanelFix

    But may be the reason is that SP 2013 doesn't use 

    return _spFormOnSubmitWrapper();

    anymore. For me the I have a form tag for the complete page with the following action

    WebForm_OnSubmit()

    Any hints for this?

    Thanks Bernhard

    Monday, July 15, 2013 7:29 AM
  • Hi Narahari,

    thanks. I tried a new webpartpage. In my webpart I just added two labels a button and the updatepanel... 

    I added the script manager and the updatepanelfix but no luck... The code behind works (changes the label with the current date/ time but still a full page reload...

    This is the tutorial I followed: http://weblogs.mysharepoint.de/blogs/fabianm/archive/2008/06/28/ajax-funktionen-in-sharepoint-webparts-integrieren.aspx  (in German)

    Thanks Bernhard


    Monday, July 15, 2013 7:33 AM
  • Hi Bernhard,

    Few things to try -

    1) Try this in a site without any custom branding or any other webparts (to make sure no other Page errors conflict with the ajax logic)

    2) Remove script manager and update panel fix. They are not required under normal circumstances.

    3) Try this in a custom application page (layouts page) instead of a visual webpart.

    4) Have the IE developer console's debugging on so as to catch any kind of JS/Ajax error.

    Narahari

    Monday, July 15, 2013 7:54 AM
  • Hi Narahari,

    thanks.. 3) as custom application page it works... It looks like that updatepanel doesn't work as sandbox solution. As farm solution it works "good".

    Unfortenatly I'm using a hosted Setup of Sharepoint with host-header based SiteCollections.. So I can deploy the solution only for "all" customers... 

    also the webpart and contenttypes defines in the soultion don't appear... but possibly based on my limited knowledge.. :-) Still learning..

    Bernhard

    Monday, July 15, 2013 6:08 PM
  • as per my experience this happens with custom master pages. its due to the fact the SPWebPartManager server tag comes out of the <form></form> (<SharePoint:SharePointForm></SharePoint:SharePointForm>) tags. To sort out this please move the <asp:ScriptManager> and <WebPartPages:SPWebPartManager> inside the form tags.

    Finally it should look like below :

    <SharePoint:SharePointForm onsubmit="if (typeof(_spFormOnSubmitWrapper) != 'undefined') {return _spFormOnSubmitWrapper();} else {return true;}" runat="server">

    <SharePoint:AjaxDelta id="DeltaSPWebPartManager" runat="server">
            <WebPartPages:SPWebPartManager runat="Server"/>
        </SharePoint:AjaxDelta>

    <asp:ScriptManager id="ScriptManager" runat="server" EnablePageMethods="false" EnablePartialRendering="true" EnableScriptGlobalization="false" EnableScriptLocalization="true" />

    thanks,

    Ammar

    please refer following links for more details:

    http://social.technet.microsoft.com/Forums/sharepoint/en-US/3fc90f9d-fddc-402f-bf5f-9f764c4c0ff2/custom-sharepoint-master-page-and-ajax-functionality

    http://social.technet.microsoft.com/Forums/sharepoint/en-US/83495ca1-6398-4b01-9e68-1ab6a372cbec/ajax-controls-not-working-for-custom-master-pages-in-share-point-2010




    • Edited by AmmarBIZ Monday, July 15, 2013 9:20 PM ....)
    Monday, July 15, 2013 8:54 PM
  • Hello Ammar,

    thanks for sharing your experience. Unfortenatly my seattle.master is OOB (out of the box) like you suggested...

    Thanks

    Bernhard 

    Thursday, July 18, 2013 5:22 AM
  • Hi Bernhard,

    Unfortunately you cannot use an update panel in sandboxed solutions. The reason is -

    The SB creates its own copy of the Page object and “copies” some information from the real Page object to the SB page object – but not everything such as the ScriptMgr reference etc.     : Wictor Wilen

    http://www.sharepointalex.co.uk/index.php/2010/12/cannot-use-an-updatepanel-in-a-sharepoint-2010-sandbox-solution/

    For sandboxed solutions, the best alternative is to use CSOM or REST Apis (very exhaustive and easy in 2013) to avoid postbacks.

    Hope it helps :-)

    Narahari


    Thursday, July 18, 2013 6:09 AM
  • It helped me out in my custom master page.

    Thanks 


    Mayank Nigam

    Thursday, December 26, 2013 12:45 PM
  • I'm having this same problem, I'm on a Farm Solution and I have tried all above,still no luck! it's driving me crazy! I tried an application page with an empty masterpage;every thing is fine but in the OOB Master page all I get is this Error :

    Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters,  .......

    any one has any more ideas?! :/

    Saturday, June 07, 2014 11:47 AM