niedziela, 21 czerwca 2015

How to use UpdatePanel with LVWP in SharePoint 2010 WebPart?

This is example of classic Web Part (i.e. not Visual Web Part) with UpdatePanel and ListViewWebPart put on it.

First assure that you have this using statement:
using System.Web.UI;
and you reference in your project System.Web.Extensions library. Otherwise you won’t be able to use UpdatePanel control.
Here is the sample WebPart class:

[ToolboxItemAttribute(false)]
public class MyWP : System.Web.UI.WebControls.WebParts.WebPart
{
    TextBox txtExample1;
    TextBox txtExample1;
    ListViewWebPart lvwp;
    SPList list;
    UpdatePanel panelMain;
   
    protected override void CreateChildControls()
    {
        panelMain = new UpdatePanel();
        panelMain.UpdateMode = UpdatePanelUpdateMode.Conditional;

        txtExample1 = new TextBox();
        txtExample2 = new TextBox();

        list = SPContext.Current.Web.GetList(SPUrlUtility.CombineUrl(SPContext.Current.Web.Url, "Lists/MyList"));
        lvwp = new ListViewWebPart();
        lvwp.ListName = list.ID.ToString("B").ToUpper();
        lvwp.ViewGuid = list.DefaultView.ID.ToString("B").ToUpper();
        lvwp.ChromeType = PartChromeType.None;

        Controls.Add(new LiteralControl(" Label1: "));
        Controls.Add(txtExample1);
        Controls.Add(new LiteralControl(" Label2: "));
        Controls.Add(txtExample1);
        panelMain.ContentTemplateContainer.Controls.Add(lvwp);
        this.Controls.Add(panelMain);
    }
}



Brak komentarzy:

Prześlij komentarz