Swetha Sankaran

Swetha Sankaran

  • NA
  • 52
  • 35.4k

Custom Web Part with CheckBoxList values lost on PostBack.

May 6 2009 3:08 PM
Hi all,

I am trying to pass filter values from a custom webpart to a consumer web part. The passed vlaues are listed in a CheckBoxList. The databinding occurs in the GetValues method.

I have 2 issues:

a) When i select the values from the consumer web part(checkboxlist) and hit apply(i have added a imagebutton with autopostback attribute set to true) the checked values appear in a comma seperated string within a textbox but the values are lost after postback.

b) If I take the databind from getvalues and put it in Page_LoadComplete with if(!this.Page.IsPostBack) then, the values dont even appear in the checkboxlist.

How do i resolve this issue?

I'm pretty stumped. I've been staring at this thing for over 2 days now. Please find attached the code i'm working with. There is a javacript handler attached to the checkboxlist that correctly identifies the values selected. I guess it gets messed up on PostBack event.

[ConnectionConsumer("Input Values")]
public void GetValues(ITransformableFilterValues values)
{
foreach (string val in values.ParameterValues)
{
//this.Provider_Values += this.Provider_Values != " " ?","+ "'" + val +"'" : "'" + val + "'" ;
this.Provider_Values = val;
this.Provider_Name = values.ParameterName;
ds = new SqlDataSource();
ds.ID = "Source ID";
ds.ConnectionString = cString;
ds.SelectCommand = this.SQLSelectCommand;//"select distinct " + cName + " from " + tName + " where " + this.Provider_Name+ " = '" + this.Provider_Values+ "';";
cBList.DataTextField = cName;
cBList.DataValueField = cName;
cBList.DataSource = ds;
cBList.ID = "List ID";
cBList.Attributes.Add("onclick", "FindSelectedItems(this," + tB.ClientID + ");");
cBList.DataBind();
}

}
public void BuildControls()
{
try
{
cBList = new CheckBoxList();
this.Controls.Add(cBList);
}
//Sql exception cought.
catch (Exception ex)
{
ex1 = ex.Message;
}
}

protected override void CreateChildControls()
{
this.BuildControls();
base.CreateChildControls();
}

protected override void OnInit(EventArgs e)
{
this.Page.LoadComplete += new EventHandler(Page_LoadComplete);
base.OnInit(e);
}

void Page_LoadComplete(object sender, EventArgs e)
{
if (this.Page.IsPostBack && !String.IsNullOrEmpty(this.Provider_Name) && String.IsNullOrEmpty(this.Provider_Values))
{
ds.SelectCommand = "select distinct " + cName + " from " + tName + " where " + this.Provider_Name + " = '" + this.Provider_Values + "';";

}

}