Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

custom text filter web part using visual studio

$
0
0

i used next code for creating text filter web part that searching text in list/document library 'Наслов' field. i deployed my web part but when i tryed that add to page i error: 

on this page it is not possible to install or import a web part or control the web form. it was not possible to find a type or not registered as safe

i used next link for resolving of my problem but nothing

https://sharepoint.stackexchange.com/questions/11524/the-type-is-not-registered-as-safe-when-trying-to-add-a-web-part-installed-by

https://social.msdn.microsoft.com/Forums/office/en-US/3c6f572b-fc0a-4be2-81c5-28d1220edcab/adding-a-custom-webpart-to-webpart-page-not-a-safe-control-issue?forum=sharepointdevelopment

my code on .cs page

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using WebPart = Microsoft.SharePoint.WebPartPages.WebPart;
using Microsoft.SharePoint.WebPartPages;
using System.Web.UI.WebControls.WebParts;
using System.Xml;

namespace custom_text_filter_web_part.customtextfilter
{
    [ToolboxItemAttribute(false)]
    public class customtextfilter : WebPart
    {
        TextBox tbA;
   //     TextBox tbB;
        Button filterButton;
        UpdatePanel mainUpdatePanel;
        ListViewWebPart lvwp;
        SPList list;

        protected override void CreateChildControls()
        {

            mainUpdatePanel = new UpdatePanel();
            mainUpdatePanel.UpdateMode = UpdatePanelUpdateMode.Conditional;

            tbA = new TextBox();
        //    tbB = new TextBox();

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



            filterButton = new Button();
            filterButton.Text = "Тражи";
            filterButton.Click += new EventHandler(filterButton_Click);



            Controls.Add(new LiteralControl(" Nom : "));
            Controls.Add(tbA);
         //   Controls.Add(new LiteralControl(" Prenom : "));
           // Controls.Add(tbB);
            mainUpdatePanel.ContentTemplateContainer.Controls.Add(filterButton);
            mainUpdatePanel.ContentTemplateContainer.Controls.Add(lvwp);


            this.Controls.Add(mainUpdatePanel);
        }

        private void filterButton_Click(object sender, EventArgs e)
        {
            string query = string.Empty;
            string tempAdding = string.Empty;
            if (!string.IsNullOrEmpty(tbA.Text))
            {
                query = "<Contains><FieldRef Name='Наслов' /><Value Type='Text'>" + tbA.Text + "</Value></Contains>";
            }
        //    if (!string.IsNullOrEmpty(tbB.Text))
          //  {
            //    tempAdding = "<Contains><FieldRef Name='Prenom' /><Value Type='Text'>" + tbB.Text + "</Value></Contains>";
              //  query = (query.Length > 0 ? "<And>" + query + tempAdding + "</And>" : tempAdding);
            //}

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(lvwp.ListViewXml);
            XmlNode queryNode = doc.SelectSingleNode("//Query");
            XmlNode whereNode = queryNode.SelectSingleNode("Where");

            if (whereNode != null) queryNode.RemoveChild(whereNode);
            XmlNode newNode = doc.CreateNode(XmlNodeType.Element, "Where", String.Empty);
            newNode.InnerXml = query.ToString();
            queryNode.AppendChild(newNode);
            lvwp.ListViewXml = doc.OuterXml;


        }
    }
}


Viewing all articles
Browse latest Browse all 11571

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>