AJAX UpdatePanel lost focus

M

Madison

Hi There,
I'm writing web application VB VS2008 with ajax. My page has user control
and textboxes. I group the textbox together and have 3 <asp:updatePanel ...
updatemode="Conditional"> each group has about 6 textboxes each textboxes
has AutoPostBack=true when I go to the third textbox with focus on, I cannot
type any characters to the box. Please helps. Thanks.
 
Z

Zhi-Qiang Ni[MSFT]

Hi Madison,

I have made a test application based on your description. After testing it,
I found that if we type some value into the first TextBox and then click
the second one, the cursor would disappear and we cannot type value into
the second one. Please tell me whether this behavior is the same to what
your mentioned.

If so, let me explain the cause of the behavior first.

We type some values into the first TextBox and then click the other place
of the window, the page would be refreshed because we set the AutoPostBack
property of the TextBox with true. Although we click the second TextBox,
the application would run the server side post back firstly whether these
controls are inside the UpdatePanel or not. The cursor which is inside the
second TextBox would disappear because the page's post back. This is the
default setting by the ASP.NET Life-cycle.

If these TextBoxes are placed into an UpdatePanel, we cannot see the
refresh of the page, so, the cursor's disappearance would be weird.

To make a workaround, we can set the AutoPostBack property with false. In
the second TextBox's client side click event, doPostBack and store the
current TextBox into a HiddenField. In the end, set the focus() function
after the asynchronous request is ended.

Refer to this sample:
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="TestUpdatePanel.aspx.vb"
Inherits="_44456996.TestUpdatePanel" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:HiddenField ID="HF1" runat="server" />
<div style="border-style: solid; border-width: thin">
TextBoxes outside the UpdatePanel<br />
Type into first TextBox and then click the second one,<br />
the page would be refreshed.<br />
<asp:TextBox ID="TextBox1" runat="server"
onclick="TextBoxOnClick(this)" AutoPostBack="false"></asp:TextBox><br />
<asp:TextBox ID="TextBox2" runat="server"
onclick="TextBoxOnClick(this)" AutoPostBack="false"></asp:TextBox><br />
<asp:TextBox ID="TextBox3" runat="server"
onclick="TextBoxOnClick(this)" AutoPostBack="false"></asp:TextBox><br />
</div>
<hr />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="border-style: solid; border-width: thin">
TextBoxes inside the UpdatePanel<br />
Type into first TextBox and then click the second
one,<br />
the page would NOT be refreshed.<br />
That's what your mentioned.<br />
<asp:TextBox ID="TextBox4" runat="server"
onclick="TextBoxOnClick(this)" AutoPostBack="false"></asp:TextBox><br />
<asp:TextBox ID="TextBox5" runat="server"
onclick="TextBoxOnClick(this)" AutoPostBack="false"></asp:TextBox><br />
<asp:TextBox ID="TextBox6" runat="server"
onclick="TextBoxOnClick(this)" AutoPostBack="false"></asp:TextBox><br />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>

<script type="text/javascript">

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(
function(sender, e) {
if ($get("HF1").value) {
var textbox = $get($get("HF1").value);
textbox.select();
textbox.focus();
}
});

function TextBoxOnClick(tb) {
if ($get("HF1").value != tb.id) {
$get("HF1").value = tb.id;
__doPostBack(tb.id, "");
}
}

</script>

</form>
</body>
</html>


Note that, to make these script run correctly, please place the script tag
under the ScriptManager control.

Another choice is set the AutoPostBack property with false and use a Button
to make a post back.

Meanwhile, I think these tutorials of the UpdatePanel can help you use it
and understand the AJAX function more clearly:

http://www.asp.net/AJAX/Documentation/Live/overview/UpdatePanelOverview.aspx
http://www.asp.net/AJAX/Documentation/Live/tutorials/UsingUpdatePanelControl
s.aspx

Understanding Partial Page Updates with ASP.NET AJAX
http://www.asp.net/learn/ajax/tutorial-01-cs.aspx

How Do I:Implement Dynamic Partial-Page Updates with ASP.NET AJAX?
http://www.asp.net/learn/ajax-videos/video-78.aspx

How Do I:Use JavaScript to Refresh an ASP.NET AJAX UpdatePanel?
http://www.asp.net/learn/ajax-videos/video-172.aspx

How Do I:Use the Conditional UpdateMode of the UpdatePanel?
http://www.asp.net/learn/ajax-videos/video-177.aspx

How Do I:Trigger an UpdatePanel Refresh from a DropDownList Control?
http://www.asp.net/learn/ajax-videos/video-183.aspx

How To Dynamically Change CSS Using the ASP.NET AJAX UpdatePanel
http://www.asp.net/learn/ajax-videos/video-285.aspx

--
Sincerely,

Zhi-Qiang Ni

Microsoft Online Support


==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================

--------------------
| Thread-Topic: AJAX UpdatePanel lost focus
| thread-index: AcqTs/64Rn3xAuuZRU6L+HzRGFvxbg==
| X-WBNR-Posting-Host: 165.189.6.46
| From: Madison <[email protected]>
| Subject: AJAX UpdatePanel lost focus
| Date: Tue, 12 Jan 2010 10:21:01 -0800
| Lines: 6
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4325
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Path: TK2MSFTNGHUB02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:95729
| NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi There,
| I'm writing web application VB VS2008 with ajax. My page has user
control
| and textboxes. I group the textbox together and have 3 <asp:updatePanel
...
| updatemode="Conditional"> each group has about 6 textboxes each textboxes

| has AutoPostBack=true when I go to the third textbox with focus on, I
cannot
| type any characters to the box. Please helps. Thanks.
|
 
M

Madison

Thank you for your reply.
Here is my coding and problems that I try to do

<asp:UpdatePanel ID="UpdatePanel4" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table border="1" style="border-collapse:collapse">
<tr>
<td colspan="2"><b>Calculation of assessable revenues for
remainder and telephone relay addessement purposes:</b></td>
<td align="right">Amount<br /><i>(000's)</i></td>
<td style="width:20%"> </td>
</tr>
<tr>
<td valign="top">1.</td>
<td valign="top">Gross Operating Revenues—Wisconsin
(including interstate revenues)</td>
<td align="right"><span
class="required">*</span><asp:TextBox ID="GrossOperateRev" runat="server"
CssClass="enabledRight" Width="110px" AutoPostBack="true" /></td>
<td><asp:Label ID="lblGrossOperateRev" runat="server"
CssClass="required" /></td>
</tr>
<tr>
<td valign="top">2.</td>
<td valign="top">Less: Inbound interstate 800 and collect
revenues billed to customers outside of Wisconsin and included on line 1</td>
<td align="right"><span
class="required">*</span><asp:TextBox ID="InboundRev" runat="server"
CssClass="enabledRight" Width="110px" AutoPostBack="true" /></td>
<td><asp:Label ID="lblInboundRev" runat="server"
CssClass="required" /></td>
</tr>
<tr>
<td valign="top">3.</td>
<td valign="top">Less: Current year write-offs of
uncollectible revenues </td>
<td align="right"><span
class="required">*</span><asp:TextBox ID="CurrWriteOff" runat="server"
CssClass="enabledRight" Width="110px" AutoPostBack="true" /></td>
<td><asp:Label ID="lblCurrWriteOff" runat="server"
CssClass="required" /></td>
</tr>
<tr>
<td valign="top">4.</td>
<td valign="top">Plus: Current year collection of operating
revenues previously written off</td>
<td align="right"><span
class="required">*</span><asp:TextBox ID="CurrCollectRev" runat="server"
CssClass="enabledRight" Width="110px" AutoPostBack="true" /></td>
<td><asp:Label ID="lblCurrCollectRev" runat="server"
CssClass="required" /></td>
</tr>
<tr>
<td valign="top">5.</td>
<td valign="top">Less: Revenues included in line 1 that are
not assessable for remainder and telephone relay assessment purposes</td>
<td align="right"><span
class="required">*</span><asp:TextBox ID="RevNotAsses" runat="server"
CssClass="enabledRight" Width="110px" AutoPostBack="true" /></td>
<td><asp:Label ID="lblRevNotAsses" runat="server"
CssClass="required" /></td>
</tr>
<tr>
<td valign="top">6.</td>
<td valign="top">Total assessable revenues for remainder and
relay assessment purposes</td>
<td align="right"><asp:TextBox ID="TotalAssesRev"
runat="server" CssClass="disabledRight" Width="110px" ReadOnly="true"
Font-Bold="true" /></td>
<td> </td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>

The textbox for no.6 will have the total values of 1-5 and everytime the
value change the line 6 total will get update. The AutoPostsBack need to set
to true for re-calculate the line 6. Each textbox 1-5 have the the
TextChanged event that call the function to calculate the total then follow
by ScriptManager1.SetFocus(textboxname.ClientID) to set focus on the next
box. I can see the cursor at the next textbox but I cannot enter any values
to the box. This is only one group of the textbox, I will have more group of
textbox familiar to this in the page. I cannot use the button to calculate
because it means that users must click button everytime they enter the
values.

Any suggestion would be appreciate. Thanks.
 
Z

Zhi-Qiang Ni[MSFT]

Hi Madison,

I have explained that if we set the AutoPostBack with true, the focus of
TextBox would always disappear by the page's reloaded. Although we can set
focus on the Control which makes this post back by using the ScriptManager
class setFocus method, there is no way to know which control is clicked.

So, I think we have to set the AutoPostBack with false to enable the client
side behavior. As a workaround, we can use the Timer control to make a post
back and calculate the sum for TextBox6.

Refer to this:

<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="TestUpdatePanel.aspx.vb"
Inherits="_44456996.TestUpdatePanel" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="border-style: solid; border-width: thin">
Value1:<asp:TextBox ID="TextBox1" runat="server"
AutoPostBack="false"></asp:TextBox>
<asp:Label ID="Label1" runat="server"
Text="Label"></asp:Label><br />
Value2:<asp:TextBox ID="TextBox2" runat="server"
AutoPostBack="false"></asp:TextBox>
<asp:Label ID="Label2" runat="server"
Text="Label"></asp:Label><br />
Value3:<asp:TextBox ID="TextBox3" runat="server"
AutoPostBack="false"></asp:TextBox>
<asp:Label ID="Label3" runat="server"
Text="Label"></asp:Label><br />
Value4:<asp:TextBox ID="TextBox4" runat="server"
AutoPostBack="false"></asp:TextBox>
<asp:Label ID="Label4" runat="server"
Text="Label"></asp:Label><br />
Value5:<asp:TextBox ID="TextBox5" runat="server"
AutoPostBack="false"></asp:TextBox>
<asp:Label ID="Label5" runat="server"
Text="Label"></asp:Label><br />
SUM:<asp:TextBox ID="TextBox6" runat="server"
AutoPostBack="false" ReadOnly="true"></asp:TextBox><br />
<asp:Timer ID="Timer1" runat="server" Interval="2000">
</asp:Timer>
</div>
<asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</div>

<script runat="server">
Private Sub Sum()

If String.IsNullOrEmpty(TextBox1.Text) Then
Label1.Text = 0
Else
Label1.Text = TextBox1.Text
End If
If String.IsNullOrEmpty(TextBox2.Text) Then
Label2.Text = 0
Else
Label2.Text = TextBox2.Text
End If
If String.IsNullOrEmpty(TextBox3.Text) Then
Label3.Text = 0
Else
Label3.Text = TextBox3.Text
End If
If String.IsNullOrEmpty(TextBox4.Text) Then
Label4.Text = 0
Else
Label4.Text = TextBox4.Text
End If
If String.IsNullOrEmpty(TextBox5.Text) Then
Label5.Text = 0
Else
Label5.Text = TextBox5.Text
End If
TextBox6.Text = (CInt(Label1.Text) + CInt(Label2.Text) +
CInt(Label3.Text) + CInt(Label4.Text) + CInt(Label5.Text)).ToString

End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Sum()
End Sub

</script>

</form>
</body>
</html>


Please test it and let me know the result.

--
Sincerely,

Zhi-Qiang Ni

Microsoft Online Support


==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
 
Z

Zhi-Qiang Ni[MSFT]

Hi Madison,

I have modified some of my code, maybe this behavior can be more smoother.
I use a HiddenField to store the clicked TextBox's ID and then setfocus
back in the Timer's tick event.

Here is the code:
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="TestUpdatePanel.aspx.vb"
Inherits="_44456996.TestUpdatePanel" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:HiddenField ID="HF1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="border-style: solid; border-width: thin">
Value1:<asp:TextBox ID="TextBox1" runat="server"
onclick="TextBoxOnClick(this)" onblur="TextBoxOnBlur(this)"
AutoPostBack="false"></asp:TextBox>
<asp:Label ID="Label1" runat="server"
Text="Label"></asp:Label><br />
Value2:<asp:TextBox ID="TextBox2" runat="server"
onclick="TextBoxOnClick(this)" onblur="TextBoxOnBlur(this)"
AutoPostBack="false"></asp:TextBox>
<asp:Label ID="Label2" runat="server"
Text="Label"></asp:Label><br />
Value3:<asp:TextBox ID="TextBox3" runat="server"
onclick="TextBoxOnClick(this)" onblur="TextBoxOnBlur(this)"
AutoPostBack="false"></asp:TextBox>
<asp:Label ID="Label3" runat="server"
Text="Label"></asp:Label><br />
Value4:<asp:TextBox ID="TextBox4" runat="server"
onclick="TextBoxOnClick(this)" onblur="TextBoxOnBlur(this)"
AutoPostBack="false"></asp:TextBox>
<asp:Label ID="Label4" runat="server"
Text="Label"></asp:Label><br />
Value5:<asp:TextBox ID="TextBox5" runat="server"
onclick="TextBoxOnClick(this)" onblur="TextBoxOnBlur(this)"
AutoPostBack="false"></asp:TextBox>
<asp:Label ID="Label5" runat="server"
Text="Label"></asp:Label><br />
SUM:<asp:TextBox ID="TextBox6" runat="server"
AutoPostBack="false" ReadOnly="true"></asp:TextBox><br />
<asp:Timer ID="Timer1" runat="server" Interval="2000">
</asp:Timer>
</div>
<asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</div>

<script type="text/javascript">
function TextBoxOnClick(tb) {
$get("HF1").value = tb.id;
}

function TextBoxOnBlur(tb) {
$get("HF1").value = "";
}
</script>

<script runat="server">
Private Sub Sum()

If String.IsNullOrEmpty(TextBox1.Text) Then
Label1.Text = 0
Else
Label1.Text = TextBox1.Text
End If
If String.IsNullOrEmpty(TextBox2.Text) Then
Label2.Text = 0
Else
Label2.Text = TextBox2.Text
End If
If String.IsNullOrEmpty(TextBox3.Text) Then
Label3.Text = 0
Else
Label3.Text = TextBox3.Text
End If
If String.IsNullOrEmpty(TextBox4.Text) Then
Label4.Text = 0
Else
Label4.Text = TextBox4.Text
End If
If String.IsNullOrEmpty(TextBox5.Text) Then
Label5.Text = 0
Else
Label5.Text = TextBox5.Text
End If

TextBox6.Text = (CInt(Label1.Text) + CInt(Label2.Text) +
CInt(Label3.Text) + CInt(Label4.Text) + CInt(Label5.Text)).ToString

End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Sum()
If Not String.IsNullOrEmpty(HF1.Value) Then
ScriptManager1.SetFocus(HF1.Value)
'ScriptManager.RegisterClientScriptBlock(Me.Page,
GetType(Page), "select", "$get('" + HF1.Value + "').select();", True)
End If
End Sub

</script>

</form>
</body>
</html>

--
Sincerely,

Zhi-Qiang Ni

Microsoft Online Support


==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
 
M

Madison

Hi Zhi-Qiang Ni,

Thank you for your sample codes. I created new page and pasted your sample
and run. It did not work for me. I still have the same problem when I try to
enter the values into the textbox.
 
Z

Zhi-Qiang Ni[MSFT]

Hi Madison,

I try to achieve your goal by using the client side function. Refer to this
code:

<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="TestClientFunction.aspx.vb"
Inherits="_44456996.TestClientFunction" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:HiddenField ID="HF1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="border-style: solid; border-width: thin">
Value1:<asp:TextBox ID="TextBox1" runat="server"
onblur="TextBoxOnBlur()" onkeypress="TextBoxOnKeyPress()"
AutoPostBack="false"></asp:TextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1" runat="server" ErrorMessage="Please enter
a Number"
ControlToValidate="TextBox1"
ValidationExpression="\d+"></asp:RegularExpressionValidator>
<asp:Label ID="Label1" runat="server" ></asp:Label><br
/>
Value2:<asp:TextBox ID="TextBox2" runat="server"
onblur="TextBoxOnBlur()" onkeypress="TextBoxOnKeyPress()"
AutoPostBack="false"></asp:TextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator2" runat="server" ErrorMessage="Please enter
a Number"
ControlToValidate="TextBox2"
ValidationExpression="\d+"></asp:RegularExpressionValidator>
<asp:Label ID="Label2" runat="server" ></asp:Label><br
/>
Value3:<asp:TextBox ID="TextBox3" runat="server"
onblur="TextBoxOnBlur()" onkeypress="TextBoxOnKeyPress()"
AutoPostBack="false"></asp:TextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator3" runat="server" ErrorMessage="Please enter
a Number"
ControlToValidate="TextBox3"
ValidationExpression="\d+"></asp:RegularExpressionValidator>
<asp:Label ID="Label3" runat="server" ></asp:Label><br
/>
Value4:<asp:TextBox ID="TextBox4" runat="server"
onblur="TextBoxOnBlur()" onkeypress="TextBoxOnKeyPress()"
AutoPostBack="false"></asp:TextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator4" runat="server" ErrorMessage="Please enter
a Number"
ControlToValidate="TextBox4"
ValidationExpression="\d+"></asp:RegularExpressionValidator>
<asp:Label ID="Label4" runat="server" ></asp:Label><br
/>
Value5:<asp:TextBox ID="TextBox5" runat="server"
onblur="TextBoxOnBlur()" onkeypress="TextBoxOnKeyPress()"
AutoPostBack="false"></asp:TextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator5" runat="server" ErrorMessage="Please enter
a Number"
ControlToValidate="TextBox5"
ValidationExpression="\d+"></asp:RegularExpressionValidator>
<asp:Label ID="Label5" runat="server" ></asp:Label><br
/>
SUM:<asp:TextBox ID="TextBox6" runat="server"
AutoPostBack="true" ReadOnly="true"></asp:TextBox><br />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>

<script type="text/javascript">

function TextBoxOnBlur(tb) {
Sum();
}

function TextBoxOnKeyPress() {
if (event.keyCode == 13) {
Sum();
}
}

function Sum() {

if (!Page_IsValid) { return; }

var value = new Array(5);
var SumValue = 0;

for (i = 1; i < 6; i++) {
if ($get("TextBox" + i).value == "") {
value = 0;
} else {
value = parseInt($get("TextBox" + i).value);
}

$get("Label" + i).innerHTML = value;
SumValue = SumValue + value;
}

$get("TextBox6").value = SumValue.toString();
}

</script>

</form>
</body>
</html>

--
Sincerely,

Zhi-Qiang Ni

Microsoft Online Support


==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================

--------------------
| Thread-Topic: AJAX UpdatePanel lost focus
| thread-index: AcqVLFe77QoByPq0RQOM9yTz7MzwkA==
| X-WBNR-Posting-Host: 165.189.6.46
| From: Madison <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: RE: AJAX UpdatePanel lost focus
| Date: Thu, 14 Jan 2010 07:15:01 -0800
| Lines: 157
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4325
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Path: TK2MSFTNGHUB02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:95775
| NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi Zhi-Qiang Ni,
|
| Thank you for your sample codes. I created new page and pasted your
sample
| and run. It did not work for me. I still have the same problem when I try
to
| enter the values into the textbox.
|
|
 
M

Madison

Hi Zhi-Qiang Ni,

Thank you for your help. Your samples for using the client side give me the
idea that I will switch my coding to use javascript for display the total
check and validation. I still have the server side validation before saving
to database. I thought that AJAX will help me with less coding but I guess
not. I hope that the new release VS2010 will make the things better. Thank
you again for your helps.


Zhi-Qiang Ni said:
Hi Madison,

I try to achieve your goal by using the client side function. Refer to this
code:

<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="TestClientFunction.aspx.vb"
Inherits="_44456996.TestClientFunction" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:HiddenField ID="HF1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="border-style: solid; border-width: thin">
Value1:<asp:TextBox ID="TextBox1" runat="server"
onblur="TextBoxOnBlur()" onkeypress="TextBoxOnKeyPress()"
AutoPostBack="false"></asp:TextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1" runat="server" ErrorMessage="Please enter
a Number"
ControlToValidate="TextBox1"
ValidationExpression="\d+"></asp:RegularExpressionValidator>
<asp:Label ID="Label1" runat="server" ></asp:Label><br
/>
Value2:<asp:TextBox ID="TextBox2" runat="server"
onblur="TextBoxOnBlur()" onkeypress="TextBoxOnKeyPress()"
AutoPostBack="false"></asp:TextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator2" runat="server" ErrorMessage="Please enter
a Number"
ControlToValidate="TextBox2"
ValidationExpression="\d+"></asp:RegularExpressionValidator>
<asp:Label ID="Label2" runat="server" ></asp:Label><br
/>
Value3:<asp:TextBox ID="TextBox3" runat="server"
onblur="TextBoxOnBlur()" onkeypress="TextBoxOnKeyPress()"
AutoPostBack="false"></asp:TextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator3" runat="server" ErrorMessage="Please enter
a Number"
ControlToValidate="TextBox3"
ValidationExpression="\d+"></asp:RegularExpressionValidator>
<asp:Label ID="Label3" runat="server" ></asp:Label><br
/>
Value4:<asp:TextBox ID="TextBox4" runat="server"
onblur="TextBoxOnBlur()" onkeypress="TextBoxOnKeyPress()"
AutoPostBack="false"></asp:TextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator4" runat="server" ErrorMessage="Please enter
a Number"
ControlToValidate="TextBox4"
ValidationExpression="\d+"></asp:RegularExpressionValidator>
<asp:Label ID="Label4" runat="server" ></asp:Label><br
/>
Value5:<asp:TextBox ID="TextBox5" runat="server"
onblur="TextBoxOnBlur()" onkeypress="TextBoxOnKeyPress()"
AutoPostBack="false"></asp:TextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator5" runat="server" ErrorMessage="Please enter
a Number"
ControlToValidate="TextBox5"
ValidationExpression="\d+"></asp:RegularExpressionValidator>
<asp:Label ID="Label5" runat="server" ></asp:Label><br
/>
SUM:<asp:TextBox ID="TextBox6" runat="server"
AutoPostBack="true" ReadOnly="true"></asp:TextBox><br />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>

<script type="text/javascript">

function TextBoxOnBlur(tb) {
Sum();
}

function TextBoxOnKeyPress() {
if (event.keyCode == 13) {
Sum();
}
}

function Sum() {

if (!Page_IsValid) { return; }

var value = new Array(5);
var SumValue = 0;

for (i = 1; i < 6; i++) {
if ($get("TextBox" + i).value == "") {
value = 0;
} else {
value = parseInt($get("TextBox" + i).value);
}

$get("Label" + i).innerHTML = value;
SumValue = SumValue + value;
}

$get("TextBox6").value = SumValue.toString();
}

</script>

</form>
</body>
</html>

--
Sincerely,

Zhi-Qiang Ni

Microsoft Online Support


==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================

--------------------
| Thread-Topic: AJAX UpdatePanel lost focus
| thread-index: AcqVLFe77QoByPq0RQOM9yTz7MzwkA==
| X-WBNR-Posting-Host: 165.189.6.46
| From: Madison <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: RE: AJAX UpdatePanel lost focus
| Date: Thu, 14 Jan 2010 07:15:01 -0800
| Lines: 157
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4325
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Path: TK2MSFTNGHUB02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:95775
| NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi Zhi-Qiang Ni,
|
| Thank you for your sample codes. I created new page and pasted your
sample
| and run. It did not work for me. I still have the same problem when I try
to
| enter the values into the textbox.
|
|

.
 
Z

Zhi-Qiang Ni[MSFT]

Hi Madison,

Thanks for your understanding of my supporting. The Ajax does help us
enable the asynchronous post back and partial refresh of the page with less
coding. However, the problem-we cannot stay the cursor in the client side
TextBox after a PostBack - is a default behavior whether we use the
UpdatePanel or not. I have explained the reason of it in my last reply. The
page needs to reload after the first TextBox is on blur. So, it's easy to
focus back to the first TextBox but hard to remember the client side click
of the next TextBox.

You can enjoy the other convenient and useful functions of the ASP.NET AJAX
and AjaxControlToolkit:
http://www.asp.net/ajax/
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Default.aspx

--
Sincerely,

Zhi-Qiang Ni

Microsoft Online Support


==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================

--------------------
| Thread-Topic: AJAX UpdatePanel lost focus
| thread-index: AcqV+WwQXiU1Nt3nSCe1ILIw4+BHNg==
| X-WBNR-Posting-Host: 165.189.6.46
| From: Madison <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: RE: AJAX UpdatePanel lost focus
| Date: Fri, 15 Jan 2010 07:43:02 -0800
| Lines: 196
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4325
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Path: TK2MSFTNGHUB02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:95795
| NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi Zhi-Qiang Ni,
|
| Thank you for your help. Your samples for using the client side give me
the
| idea that I will switch my coding to use javascript for display the total
| check and validation. I still have the server side validation before
saving
| to database. I thought that AJAX will help me with less coding but I
guess
| not. I hope that the new release VS2010 will make the things better.
Thank
| you again for your helps.
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top