views:

173

answers:

1

I want to filter DFWP through asp:TextBox.

Using Office Designer I added DFWP with data to the page. Added asp:textbox with runat server, autopostback and ID="textBoxSearch". Created variable [var] in DFWP and in the source section chose element textBoxSearch.

Then added filter "field_1 contains [var]".

This search(filter) worked greatly for two weeks, then filter broken. Only recreating DFWP helped. After another week filter was broken. Any text in textbox was ignored by filter.

I figured out that SP can't see asp:textbox "textBoxSearch" in variable [var], because if change "contains [var]" to "contains 'some text'" it will work.

How can it be - working some time, then accidentally not?

If not using internal filter web-part, but textbox, how to fix it?

A: 

I found that SP looks to property Text of asp:TextBox and to non existing property Value. It will be changed after IIS reset. So, when SP looks to Value filter does not work.

The answer is two write your own control ascx CustomTextBox based on asp:TextBox.

Don't forget that you can't copy usual codebehind files to SP.

First, write full codebehind file and compile it to DLL(I called it SearchTextBox.dll):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


namespace WebApplication3
{
    public partial class NewTextBox : System.Web.UI.UserControl
    {
        protected global::System.Web.UI.WebControls.TextBox TextBox_PhoneSearch;

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public string Text
        {
            get { return TextBox_PhoneSearch.Text; }
            set { TextBox_PhoneSearch.Text = value; }
        }
        public string Value
        {
            get
            {
                return TextBox_PhoneSearch.Text;
            }
        }
    }
}

Then assign this DLL with keys and insert to the server GAC (or give special rights).

After that you can link the assemble with public key in ascx control file (without codebehind files). NewTextBox.ascx file:

<%@ Assembly Name ="SearchTextBox, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b341d7aadf237863"%>
<%@ Control Language="C#" AutoEventWireup="true" Inherits="WebApplication3.NewTextBox" %>
<asp:TextBox ID="TextBox_PhoneSearch" runat="server" AutoPostBack="true" class="ms-sbplain" style="width: 280px;"></asp:TextBox>

Copy NewTextBox.ascx to ...\12\TEMPLATE\CONTROLTEMPLATES\

Control NewTextBox.ascx is ready to use. We just need to register it in SP page:

<%@ Register Src="~/_controltemplates/NewTextBox.ascx" TagName="NewTextBox" TagPrefix="MyCompany" %>

And insert it to this page:

<MyCompany:NewTextBox id="TextBoxSearch" runat="server"/>
Artru