Dec 11, 2008, 11:27 PM
[FIXED] [V0.7] LoadPostData() results in NullReferenceException
<p class="MsoNormal"></p><p class="MsoNormal"></p><p class="MsoNormal">Hello All,</p>
<p class="MsoNormal">Today I ran into a strange issue with Coolite form elements
that I would like to share with the community. </p>
<p class="MsoNormal">Long story short, we have a custom server control that
initiates ICallback requests on various client side events. When we mixed
Coolite in all of a sudden the ICallback requests started throwing null reference
errors. Bellow is an example stack trace.</p>
</p>
</p>
</p>
<p class="MsoNormal">Today I ran into a strange issue with Coolite form elements
that I would like to share with the community. </p>
<p class="MsoNormal">Long story short, we have a custom server control that
initiates ICallback requests on various client side events. When we mixed
Coolite in all of a sudden the ICallback requests started throwing null reference
errors. Bellow is an example stack trace.</p>
[NullReferenceException: Object reference not set to an instance of an object.]
Coolite.Ext.Web.Hidden.set_Value(Object value) +73
Coolite.Ext.Web.Hidden.LoadPostData(String postDataKey, NameValueCollection postCollection) +160
Coolite.Ext.Web.Field.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +11
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +661
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1194
As it would turn out, the ICallback request was not posting all of the form elements Coolite was expecting. Three different form elements chocked on null value posts. After a few minor tweeks to the following pieces of code the ICallback requests resumed working.
public virtual string Text
{
get
{
return (string)this.ViewState["Text"] ?? "";
}
set
{
this.ViewState["Text"] = value;
}
}
NumberField.cs
protected override bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{
string val = postCollection[this.UniqueName];
if (!this.ReadOnly && !this.Text.Equals(val))
{
try
{
this.ViewState.Suspend();
this.Text = val != null && val.Equals(this.EmptyText) ? "" : val;
}
finally
{
this.ViewState.Resume();
}
return true;
}
return false;
}
Hidden.cs
public override object Value
{
get
{
return (string)this.ViewState["Value"] ?? "";
}
set
{
this.ViewState["Value"] = value != null ? value.ToString() : null;
}
}
<p class="MsoNormal">Cheers!</p></p>
</p>
</p>