Menu

#29 Avoid NaN in ImageButton

open
nobody
None
5
2007-11-03
2007-11-03
Andy Miller
No

See post https://sourceforge.net/forum/message.php?msg_id=4602854

There's a known problem with the standard ASP.NET ImageButton when used inside a panel. Specifically, clicking on the very top or side border can result in an exception because the x and/or y co-ordinate of the mouse ponter isn't defined.

add the following code to the Anthem ImageButton to avoid getting exceptions.
Not my code - I got it from the asp forums, but is has resolved issues on my website.

/// <summary>
/// To avoid issue when Update Panel can return NaN instead of 0 /// as discussed here http://forums.asp.net/thread/1450669.aspx
/// </summary>

protected override bool LoadPostData(string postDataKey, NameValueCollection
postCollection)
{
string xKey;
string yKey;
string xValue = postCollection[xKey = (string.Format("{0}.x", UniqueID))];
string yValue = postCollection[yKey = (string.Format("{0}.y", UniqueID))];

if (!string.IsNullOrEmpty(xValue) && !string.IsNullOrEmpty(yValue))
{
NameValueCollection postCollectionCopy = new NameValueCollection();
int x;
int y;

int.TryParse(xValue, out x);
int.TryParse(yValue, out y);

postCollectionCopy.Add(xKey, x.ToString());
postCollectionCopy.Add(yKey, y.ToString());
return base.LoadPostData(postDataKey, postCollectionCopy);
}
else
{
return false;
}
}

Discussion


Log in to post a comment.