Question : Sharepoint Webpart page load event issue

I have created 2 connected webparts for filter Sharpoint Document Library. In provider web part I am sending column name to filter, I have added inbuilt text filter web part which will send column value. and in consumer web part I am getting columnname and value from above two web parts. Now I am updating view of Shapreoint Docuemnt Library using CAML query please find the code below of cosumer and provider web part.

Issue:
When we come to the page for first time it is showing all the docuemtns present in the document lib as expected. but when I try to search for a record like dept= department1. for the first time page just refreshed with no change and if i again refresh page forcefully then i am getting expected result.


Please find the screenshot  of the webpart how it looks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
//Provider WebPart

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace EventSearchWebPart
{
    [Guid("0736764b-dc5c-404a-9c7b-188659cf2719")]
    public class EventSearchWebPart : System.Web.UI.WebControls.WebParts.WebPart, ITransformableFilterValues
    {
        public EventSearchWebPart()
        {
        }

        [ConnectionProvider("Department OR Location", "UniqueIDForRegionConnection", AllowsMultipleConnections = true)]
        public ITransformableFilterValues SetConnection() 
        { 
            return this; 
        }


        private RadioButtonList _regions;
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            _regions = new RadioButtonList(); 
            _regions.Items.Add(new ListItem("Department"));
            _regions.Items.Add(new ListItem("Location"));
            _regions.Items.Add(new ListItem("All Events")); 
            _regions.AutoPostBack = true; 
            
            this.Controls.Add(_regions);
        }

        #region ITransformableFilterValues Members

        public bool AllowAllValue
        {
            get { return true; }
        }

        public bool AllowEmptyValue
        {
            get { return false; }
        }

        public bool AllowMultipleValues
        {
            get { return false; }
        }

        public string ParameterName
        {
            get { return "Department OR Location"; }
        }

        public System.Collections.ObjectModel.ReadOnlyCollection<string> ParameterValues
        {
            get {
                EnsureChildControls(); 
                List<string> regions = new List<string>(); 
                for (int i = 0; i < _regions.Items.Count; i++) 
                { 
                    if (_regions.Items[i].Selected) 
                    { 
                        regions.Add(_regions.Items[i].Value); 
                    } 
                } 
                ReadOnlyCollection<string> result = new ReadOnlyCollection<string>(regions); 
                return result;
            }
        }

        #endregion
    }
}

//Consumer WebPart

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Collections.Generic;

namespace EventSearchWebPart
{
    [Guid("558abb6e-c442-4cda-aaeb-991d8bdc6884")]
    public class EventSearchConsumerWebPart : System.Web.UI.WebControls.WebParts.WebPart
    {
        private List<IFilterValues> _filterProviders; 
        private List<IFilterValues> FilterProviders 
        { 
            get 
            { 
                return _filterProviders; 
            } 
        }
        [ConnectionConsumer("filter", "UniqueIDForConsumer", AllowsMultipleConnections = true)]
        public void SetFilter(IFilterValues filterValues) 
        { 
            if (filterValues != null) 
            { 
                EnsureChildControls(); 
                List<ConsumerParameter> parameters = new List<ConsumerParameter>();
                parameters.Add(new ConsumerParameter("Department OR Location", ConsumerParameterCapabilities.SupportsMultipleValues | ConsumerParameterCapabilities.SupportsAllValue)); 
                parameters.Add(new ConsumerParameter("Status", ConsumerParameterCapabilities.SupportsMultipleValues | ConsumerParameterCapabilities.SupportsAllValue));
                filterValues.SetConsumerParameters(new System.Collections.ObjectModel.ReadOnlyCollection<ConsumerParameter>(parameters)); 
                this.FilterProviders.Add(filterValues); 
            } 
        }
        
        public EventSearchConsumerWebPart()
        {
            _filterProviders = new List<IFilterValues>();
        }

             protected override void OnPreRender(EventArgs e)
        {
            string filname = "";
            string filval = "";
            foreach (IFilterValues filter in FilterProviders)
            {
                //writer.WriteLine(string.Format("Parameter: {0} <br>", filter.ParameterName)); 
                if (filter.ParameterValues != null)
                {
                    foreach (string value in filter.ParameterValues)
                        if (!string.IsNullOrEmpty(value))
                        {
                            //writer.WriteLine(string.Format("  value: {0} <br>", value));
                            if (filter.ParameterName == "Department OR Location")
                                filname = value;
                            else
                            {
                                if (filter.ParameterName == "Status")
                                    filval = value;
                            }
                        }
                }
            }
            SPWeb web = SPControl.GetContextWeb(this.Context);
            web.AllowUnsafeUpdates = true;
            SPView view = web.Lists["Events01"].Views["All Documents"];
            string query = "";
             if (filname == "All Events")
                    query = "<OrderBy><FieldRef Name='Title' /></OrderBy>";
             else
            if (filname != "" && filval != "")
            {
                           
                query = "<Where><Eq><FieldRef Name='" + filname + "' /><Value Type='Text'>" + filval + "</Value></Eq></Where>";
            }
            else
                query = "<OrderBy><FieldRef Name='Title' /></OrderBy>";
            view.Query = query;
            view.Update();
                 base.OnPreRender(e);
           
        }
       
    }
}
Attachments:
 
WebpatDocLibrary
WebpatDocLibrary
 

Answer : Sharepoint Webpart page load event issue


You are not firing an event when the  department is filled in, You need some javascript to be added to the page to enable thi.
http://msdn.microsoft.com/en-us/library/ms469765.aspx has an example
Random Solutions  
 
programming4us programming4us