Saturday, March 24, 2012

UpdatePanel and Default Button

There is nothing special about my ASP.NET code below. I have a label inside the update panel, and Button1, when pressed, sets the current time to the Label.

The only thing is, Button1 is the form's default button.

It works flawlessly in the development environment. I can press ENTER endlessly and it will work without postbacks. However, in the target environment, I observe very strange behaviors.

* Pleasecheck out the pageI have on my test server. Place your cursor inside one of the text boxes and press ENTER. It works. Now press ENTER again, Then it posts back. Every other time, it posts back.

* In my actual application, again it works in the development environment. But when ENTER is pressed the second time, I get a popup box that says,

Sys.WebForms.PageRequestManagerParserException:the message received from the server could not be parsed. Commoncauses for this error are when the response is modified by calls toResponse.Write(), response filters, HttpModules, or server traceenabled.Details: Error parsing near

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server" defaultbutton="Button1">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<br />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>

<asp:Button ID="Button2" runat="server" Text="Not Default" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Default" />
</div>
</form>
</body>
</html>

Can you give your server side code.So i can find out your problem's solution.


There is very little to the server side code. Here
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partialclass _Default : System.Web.UI.Page
{

protected void Button1_Click1(object sender, EventArgs e)
{
Label3.Text ="Default button pressed. Time is " + DateTime.Now.ToString();
}
}


I think when hitting enter you are going of Focus on your app. Perhaps at the end of your method you can get focus back on your textbox through javascript or your method.

function focuxtextbox () {

document.getElementById('textbox').focus();

}


vicpal25:

I think when hitting enter you are going of Focus on your app. Perhaps at the end of your method you can get focus back on your textbox through javascript or your method.

Well, losing the focus is not the issue. It posts back every other time when I press ENTER. That it redraws the whole page every other time is a problem. When you just press the button, it works, but not when you press ENTER.


Hum, yeah I was checking out your sample app. Interesting behavior. Have you tried passing the:

UpdateMode="Conditional"

to the udpate panel?


vicpal25:

Hum, yeah I was checking out your sample app. Interesting behavior. Have you tried passing the:

UpdateMode="Conditional"

to the udpate panel?

Yes I did. Same behavior.


hello.

well, the problem is that you're partial postback isn't re-registering the button as the default button. you can see this by using fiddler. i've tried hosting the app on my machine, but iis is working correctly here. can you debug the app on the server and see the value of the _requireFocusScript field during the pre-render event of the page?


Luis Abreu:

can you debug the app on the server and see the value of the _requireFocusScript field during the pre-render event of the page?

I've noted this behavior only on the target machine, not on my development machine. So how would I go about debugging the value of the _requireFocusScript?


hello again.

yes, here on my machine i'm not seeing that behavior too. i only see it when i try to load the page from the server where you've deployed the app

well, you'll have to add a method that handlers the prereder event and then you'll have touse the watch window since you'll have to go through several non public fields:

manager._pageRequestManager._requireFocusScript


Problem resolved. Well, kinda.

A windows update for .NET fromwork 2.0 fixed it. However, it now only works for IE, but not for Firefox. I suspect that is a different issue all together.

No comments:

Post a Comment