Showing posts with label object. Show all posts
Showing posts with label object. Show all posts

Wednesday, March 28, 2012

UpdatePanel - Input string was not in a correct format

I have a simple function to expand/contract a div in an update panel to show/hide the edit controls on a page:

protectedvoid btnExpand_Click(object sender,ImageClickEventArgs e){

divControls.Visible = !divControls.Visible;

}

most of the time it works, maybe 95%, but sometimes I get that error "Input string was not in a correct format". If I try to handle the error withOnAsyncPostBackError="ScriptManager1_AsyncPostBackError" , I can grab more info but I have no idea where the error is:
source: mscorlib
stack trace:at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Int32.Parse(String s, IFormatProvider provider) at System.Web.UI.WebControls.ImageButton.LoadPostData(String postDataKey, NameValueCollection postCollection) at System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
targetsite: {Void StringToNumber(System.String, System.Globalization.NumberStyles, NumberBuffer ByRef, System.Globalization.NumberFormatInfo, Boolean)}

it may be an issue with trying to start a new request before finishing the last request. Any ideas?

We are running into the same problem. I've worked out that what's happening is, if an ImageButton is inside an UpdatePanel then something is happening when the user clicks on it.

If they click on the very top row of pixels, or the very left row of pixels on the button, the browser is posting "NaN" for the x or y coordinate of the click, and the server is barfing when it goes to parse it.

I can see this when I look at the request in Fiddler:

btnButton.x=55
btnButton.y=NaN

If the button isnot in an UpdatePanel, then it's fine (it posts 0 as the coordinate). If the user doesn't click on the very top or the very left of the image, then it's also fine.


There is another thread covering this issue here:http://forums.asp.net/thread/1458229.aspx

One on the ASP.NET team members has required some trace code, which I posted and I'm still waiting for an answer. They should be investigating the issue

Regards,

Juan


awesome, thanks guys, at least now I know why the problem was so intermittent, my button is + - so it's really small, now if only we can get M$ to fix it...

i saw a hundred of these threads, but most of them had people actually with type mismatches, hard to sift through them all


If you put BorderWidth="1px" and BorderColor="Background Color" in the <asp:ImageButton> properties I never got the error again. Hope this works for you.

Is there any update on this bug? I tried the border stuff, and it works nicely - I can't generate the error any more.

However, as a general solution, it's obviously not very good. In this particular case for us, a 1px background colour border is not a big deal, but I can certainly imagine cases where a 1 pixel borderisa big deal (like if we had a precise layout, or something).

So can someone from Microsoft please confirm that thisisan actual bug, and let us know when it'll be fixed (or has it already?)

I can provide a fairly simple test case if required.


Very useful information on this error guys, cheers. I'm eager to hear the reponse to this problem also as i'm one of those people which cannot add a 1px border to my image buttons because of the precise layout.

Smile

Thanks.


I've tried solution with 1px border but it didn't worked for me. Then I applied the following fix:

<asp:ImageButton ID="ImageButton1" runat="server" OnClientClick="if (event.offsetX==0 || event.offsetY==0) return false; " />

Very useful information

thnxSmile


Useful information......

thnxSmile


I am in SHOCK! I didn't think I would ever figure this one out. What a WEIRD bug!

Thanks for figuring this out! You deserve a raise.


For people that can't do the border hack the following may be useful.

using System.Collections.Specialized;using System.Runtime.InteropServices;using System.Web.UI;[assembly : TagPrefix("MS.Utilities.CustomControls","MS")]namespace MS.Utilities.CustomControls{/// <summary> /// To avoid issue when Update Panel can return NaN instead of 0 /// as discussed here http://forums.asp.net/thread/1450669.aspx /// </summary> [ToolboxData("<{0}:ImageButton runat=server></{0}:ImageButton>")] [ComVisible(false)]public class ImageButton : System.Web.UI.WebControls.ImageButton {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; } } }}

Monday, March 26, 2012

UpdatePanel & Opening a new window when returning from code-behind

Hi there,

Here's the OnClick event code for a button inside an UpdatePanel:

protected void btnReport_Click(object sender, EventArgs e)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "viewRepo", "<script>window.open('RepoViewer.aspx','viewReport')</script>");
}

As you can see, after returning from code-behind I want to open a new browser window with a given web form. Well, this works correctly without an UpdatePanel, or when EnablePartialRendering is set to false.

If EnablePartialRendering is set to true, a new window does not open.

Any workarounds?

-Benton

I'm having the same issue.

Rob


Hi Benton,

I'd the same problem, but I solve it, use've just to remove the tag scrip from your code (belive, it works!!!)

I used before this:

Sub wOpen(ByVal fWindow As String, ByVal fNameWin As String, ByVal fWidth As Integer, ByVal fHeight As Integer, ByVal fMenu As Boolean, ByVal fResizable As Boolean, ByVal fScroll As Boolean)
Dim strJ As String
strJ = "<script language='text/javascript'>"
strJ &= "window.open('" & fWindow & "', '" & fNameWin & "', "
strJ &= "'width=" & fWidth & ", height=" & fHeight & ", menubar="
If fMenu = True Then
strJ &= "yes"
Else
strJ &= "no"
End If
strJ &= ", resizable="
If fResizable = True Then
strJ &= "yes"
Else
strJ &= "no"
End If
strJ &= ", scrollbars="
If fScroll = True Then
strJ &= "yes"
Else
strJ &= "no"
End If
strJ &= "')<"
strJ &= "/script>"
'Page.RegisterClientScriptBlock("wOpen", strJ)
'Me.ClientScript.RegisterStartupScript(Me.Page.GetType(), "wOpen", strJ, True)
Me.ClientScript.RegisterStartupScript(Me.GetType(), "wOpen", strJ, True)
End Sub

And now I'm using:
Sub xOpen(ByVal fWindow As String, ByVal fNameWin As String, ByVal fWidth As Integer, ByVal fHeight As Integer, ByVal fMenu As Boolean, ByVal fResizable As Boolean, ByVal fScroll As Boolean)
Dim strJ As String
strJ = "window.open('" & fWindow & "', '" & fNameWin & "', "
strJ &= "'width=" & fWidth & ", height=" & fHeight & ", menubar="
If fMenu = True Then
strJ &= "yes"
Else
strJ &= "no"
End If
strJ &= ", resizable="
If fResizable = True Then
strJ &= "yes"
Else
strJ &= "no"
End If
strJ &= ", scrollbars="
If fScroll = True Then
strJ &= "yes"
Else
strJ &= "no"
End If
strJ &= "')"
Me.ClientScript.RegisterStartupScript(Me.GetType(), "xOpen", strJ, True)
End Sub

Note that I just remove the javascript tag, and it works very well.

jb.alessandro:

Hi Benton,

I'd the same problem, but I solve it, use've just to remove the tag scrip from your code (belive, it works!!!)


Note that I just remove the javascript tag, and it works very well.

Hi JB,

I am having the same problem. I hope there is a way to fix it with my case. Below is my script. Thanks

Response.Write(

"<script>window.open('../MailCenter/mailMain.aspx?tomemid=" +Convert.ToInt32(ViewState["MemID"]) +"','_blank');</script>");

How is it possible to remove the tags in this case? I tried but it didn't work.

blumonde