Recently I have to fix this bug to enable the view state after postback.
Change the text to use Literal intead of LiteralControl.
Literal will store the view state.
In SelectedItemsTemplate.cs
Change selectedNodeText = new Literal()
var selectedNodeText = new Literal();
selectedNodeText.ID = "SelectedNodeText";
innerDiv.Controls.Add(selectedNodeText);
and when binding change it to grab Literal instead of LiteralControl
void SelectedValues_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
HtmlGenericControl liSelectNode = (HtmlGenericControl)e.Item.FindControl("SelectedNodeListItem");
HtmlAnchor lnkSelectNode = (HtmlAnchor)e.Item.FindControl("SelectedNodeLink");
Literal litSelectNodeName = (Literal)e.Item.FindControl("SelectedNodeText");
HtmlAnchor infoButton = (HtmlAnchor)e.Item.FindControl("InfoButton");
OnLoad of MNTP_DataEditor, add this before Binding Selected values
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
//add the js/css required
this.AddAllMNTPClientDependencies();
//KK.Fix for postback binding data
if (this.Page.IsPostBack)
{
//if it is postback - we need to bind it from selectedIds
//setting XML Value will give the data source and will trigger proper binding
XmlValue = ConvertToXDocument(SelectedIds);
//When first load this is run on populate form, so it has set the selectedIds.
//but on postback / this value is taken from the client and it must be setup whenever it loads it.
//So I decide to put it here.. when it is postback, we will grab the data from front end and sycn it to the control
//if it is not postback, we setup nothing except before this run, someone set it on populate the form.
}
//bind the repeater if theres a data source
if (SelectedValues.DataSource != null)
{
SelectedValues.DataBind();
}
Done…
No comments:
Post a Comment