Using Updatepanel in sharepoint 2013 web part

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.

April 3rd, 2013 3:47pm

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.

Free Windows Admin Tool Kit Click here and download it now
April 27th, 2013 11:04am

Hi,

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

Any new findings?

Thx

Bernhard

July 14th, 2013 11:45am

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";
}

Free Windows Admin Tool Kit Click here and download it now
July 14th, 2013 4:08pm

Hi Narahari,

thanks fr 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

July 14th, 2013 4:20pm

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.
Free Windows Admin Tool Kit Click here and download it now
July 15th, 2013 6:02am

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



July 15th, 2013 7:23am

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

Free Windows Admin Tool Kit Click here and download it now
July 15th, 2013 7:29am

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


July 15th, 2013 7:33am

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

Free Windows Admin Tool Kit Click here and download it now
July 15th, 2013 7:54am

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

July 15th, 2013 6:08pm

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 ....)
Free Windows Admin Tool Kit Click here and download it now
July 15th, 2013 8:54pm

Hello Ammar,

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

Thanks

Bernhard 

July 18th, 2013 5:22am

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


Free Windows Admin Tool Kit Click here and download it now
July 18th, 2013 6:09am

It helped me out in my custom master page.

Thanks 

December 26th, 2013 12:45pm

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?! :/

Free Windows Admin Tool Kit Click here and download it now
June 7th, 2014 11:47am

I have the same issue but not yet resolved.

Regards,

Suresh Kumar V.C

September 15th, 2015 12:58am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics