PDA

View Full Version : [FIXED] [V0.7] LoadPostData() results in NullReferenceException



disbell
Dec 12, 2008, 12:27 AM
<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>
[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.IPostBackDataH andler.LoadPostData(String postDataKey, NameValueCollection postCollection) +11
System.Web.UI.Page.ProcessPostData(NameValueCollec tion 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 &amp;&amp; !this.Text.Equals(val))
{
try
{
this.ViewState.Suspend();
this.Text = val != null &amp;&amp; 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>

geoffrey.mcgill
Dec 12, 2008, 2:10 PM
Hi disbell,

Thanks for pointing out the NullReference issue.

We have gone through the controls and corrected the problem.

This fix will be available with the v0.7 release.